prcomputer 2/17/2017 2:58:28 PM

Creating Service Call Labor and Expense lines in Econnect 2016 / Dynamics Web Services 2016

Hi:

Is it possible to update a Service Call to add expense and labor lines via Econnect or Web Services?  If so, can anyone point me to an example?

I have Web Services installed, and the service is working (created an employee following the example in the docs.  Below is stack trace output and the code that is failing with an 'Object reference not set to an instance of an object. exception.'  Sorry for the mess!

 at Microsoft.Dynamics.GP.BusinessLogic.HandleServiceLineDefaulting`1.DefaultKeys(ServiceDocumentKey key, List`1 lines)

   at Microsoft.Dynamics.GP.ServiceCallDefaultStrategyImplementation.DefaultExpenseLine(ServiceCall call)

   at Microsoft.Dynamics.GP.ServiceCallDefaultStrategyImplementation.DefaultingForUpdate(Object sender, BusinessObjectUpdateEventArgs e)

   at Microsoft.Dynamics.GP.ServiceCallDefaultStrategy.DefaultingForUpdate(Object sender, BusinessObjectUpdateEventArgs e)

 

 

 

 
static void createServiceExpense() {
            CompanyKey companyKey;
            Context context;
            ServiceDocumentKey serviceDocumentKey;
            ServiceCall serviceCall;
            Policy serviceCallPolicy;
 
 
            // Create an instance of the service
            DynamicsGPClient wsDynamicsGP = new DynamicsGPClient();
 
            // Create a context with which to call the service
            context = new Context();
 
            // Specify which company to use (sample company)
            companyKey = new CompanyKey();
            companyKey.Id = (1);
 
            // Set up the context
            context.OrganizationKey = (OrganizationKey)companyKey;
 
            // Create a service document key object
            serviceDocumentKey = new ServiceDocumentKey();
            serviceDocumentKey.Id = "0000000025";
            
            // Retrieve the specified service call object
            serviceCall = new ServiceCall();
            serviceCall = wsDynamicsGP.GetServiceCallByKey(serviceDocumentKey, context);
 
 
 
            //List<ServiceCallExpenseLine> serviceCallExpenseLines = new List<ServiceCallExpenseLine>();
 
            ServiceCallExpenseLine expenseLine;
            expenseLine = new ServiceCallExpenseLine();
            ServiceTechnicianKey stk = new ServiceTechnicianKey();
            stk.Id = "418";
            ItemKey itemKey = new ItemKey();
            itemKey.Id = "5-STDLABOR";
            expenseLine.ItemKey = itemKey;
            expenseLine.TechnicianKey = stk;
            Quantity qtySold = new Quantity();
            qtySold.Value = 1;
            expenseLine.QuantitySold = qtySold;
            MoneyAmount unitPrice = new MoneyAmount();
            unitPrice.Value = 99;
            expenseLine.UnitPrice = unitPrice;
            expenseLine.TotalCost = unitPrice;
 
            expenseLine.UofM = "HOUR";
             
 
 
            ServiceCallExpenseLine[] expenseLines = { expenseLine};
 
 
            serviceCall.Expenses = expenseLines;
 
 
 
            serviceCallPolicy = wsDynamicsGP.GetPolicyByOperation("UpdateServiceCall", context);
 
            wsDynamicsGP.UpdateServiceCall(serviceCall, context, serviceCallPolicy);
 
            // Display the service call customer name
            //MessageBox.Show("Customer: " + serviceCall.CustomerName);
            //Debug.WriteLine("Customer: " + serviceCall.CustomerName);
             
            // Close the service
            if (wsDynamicsGP.State != CommunicationState.Faulted)
            {
                wsDynamicsGP.Close();
            }
 
 
        }

 


 

Version: GP 2015
Section: Dynamics GP, eConnect, Web Services


Table Definition Quick Links
All Tables
SOP Tables
RM Tables
GL Tables
POP Tables
HR Tables
PM Tables
UPR Tables
IV Tables
Olympic Tables
3