Setting Role in GP Web Services yields unhandled exception

482 views Asked by At

Ultimate goal: To create a receivables document in Dynamics GP using web services having the option to provide distributions or not from a C# application.

What I am attempting: Retrieve a policy for a specific role where the account distributions behavior is set to "Distributions will be provided"

I've included a code snippet below. If I remove the setting of the context.RoleKey property everything works fine with the default role and a transaction is created with automatic distributions. However, setting the RoleKey property results in an unhandled script exception at the GetPolicyByOperation method call. I've tried using the Superuser - as indicated below. I've also tried a new role giving it access to everything. Both these roles have been used to create new versions of the Create Receivables Invoice Policy in the security console.

context.OrganizationKey = (OrganizationKey)companyKey;

RoleKey roleKey = new RoleKey();
roleKey.Id = "Superuser";

context.RoleKey = roleKey;

receivablesInvoiceCreatePolicy = wsDynamicsGP.GetPolicyByOperation("CreateReceivablesInvoice", context);
1

There are 1 answers

0
CodenameCain On BEST ANSWER

I have worked with a Microsoft employee during the GP Technical Airlift 2013 in Fargo, ND. What he found is this failure is likely a bug, which he is going to log internally. He did share a work-around with me by using the WorkOnBehalfOf property on the Context object. Here are my steps to set this up and code snippet.

  1. Create a new windows user "domainuser01"
  2. Assign domainuser01 to a role in the Dynamics Security Console which has the "Create GL Account Distributions Behavior" set to "Distributions Will Be Provided" on the "Create Receivables Invoice Policy".
  3. Grant domainuser01 Windows Authentication access to the GP databases and the Web Services database.

Code:

context.OrganizationKey = (OrganizationKey)companyKey;

receivablesInvoiceCreatePolicy = wsDynamicsGP.GetPolicyByOperation("CreateReceivablesInvoice", context);

context.WorkOnBehalfOf = "<domain>\\domainuser01";

wsDynamicsGP.CreateReceivablesInvoice(newReceivablesDoc, context, receivablesInvoiceCreatePolicy);