Update Vendor Payment Method With BAQ

Interesting! I get this new error:


## System Information ##
==================

AppServer Connection: https://centralusdtpilot01.epicorsaas.com/SaaS512Pilot
Form Name: Business Activity Query Designer
Customization Name: 
Menu ID: XABA3040
Software Version: 3.2.700.8

============

Business Layer Exception

A valid 1099 Code is required.

Exception caught in: Epicor.ServiceModel

## Error Detail ##
============

##!Correlation ID:##!  66497182-265a-4b40-a4e6-ea7cee83ffcd
##!Description:##!  A valid 1099 Code is required.
##!Program:##!  Erp.Internal.CSF.USA.dll
##!Method:##!  BeforeUpdate
##!Line Number:##!  38
##!Column Number:##!  33
##!Table:##!  Vendor
##!Field:##!  Code1099ID

## Client Stack Trace ##
==================
   at Epicor.ServiceModel.Channels.ImplBase`1.ShouldRethrowNonRetryableException(Exception ex, DataSet[] dataSets)
   at Ice.Proxy.BO.DynamicQueryImpl.RunCustomAction(DynamicQueryDataSet queryDS, String actionID, DataSet queryResultDataset)
   at Ice.Adapters.DynamicQueryAdapter.<>c__DisplayClass43_0.<RunCustomAction>b__0(DataSet datasetToSend)
   at Ice.Adapters.DynamicQueryAdapter.ProcessUbaqMethod(String methodName, DataSet updatedDS, Func`2 methodExecutor, Boolean refreshQueryResultsDataset)
   at Ice.Adapters.DynamicQueryAdapter.RunCustomAction(DynamicQueryDataSet queryDS, String actionId, DataSet updatedDS, Boolean refreshQueryResultsDataset)
   at Ice.UI.App.BAQDesignerEntry.BAQTransaction.<>c__DisplayClass386_0.<CallRunCustom>b__0(Int32& rowReturned)
   at Ice.UI.App.BAQDesignerEntry.Forms.BAQDiagramForm.ShowQueryResults(DataSet dsResults, getQueryResult getResults, ReportAdditionalInfo additionalInfo)
   at Ice.UI.App.BAQDesignerEntry.BAQTransaction.CallRunCustom()

Just spoke to the boss. It sounds like 1099 was a checkbox pulled from the old Vantage system. When I try to update the pay method for these vendors, it must try to validate the 1099. I will have to add some error checking to clean up the 1099 codes if they are missing. Thanks for helping me track this down!

I am trying to update both Code1099, and TINType within the vendor table. I only want to do this when there is not already a value in those fields. My attempt below combines everything we have done so far. But I still am getting that server side error (below).


foreach (var ttResults_iterator in (from ttResults_Row in ttResults select ttResults_Row)) // for every line in the BAQ results do this stuff...
{
       
    using (Erp.Contracts.VendorSvcContract svc = Ice.Assemblies.ServiceRenderer.GetService<Erp.Contracts.VendorSvcContract>(Db))
      {
        var dsVend = svc.GetByID(ttResults_iterator.Vendor_VendorNum);
        string msg = String.Format("VendorRowCount:{0}", dsVend.Vendor.Count().ToString());
          
            foreach ( var vendorRow in dsVend.Vendor )
            {
              msg += System.Environment.NewLine + String.Format("Vendor:{0} PMUID:{1} RowMod:{2}", vendorRow.VendorNum.ToString(), vendorRow.PMUID.ToString(), vendorRow.RowMod);
            }
          
          this.PublishInfoMessage(msg, Ice.Common.BusinessObjectMessageType.Information, Ice.Bpm.InfoMessageDisplayMode.Individual, "", "" );
        if(dsVend.Vendor[0].Code1099ID == "") 
          {dsVend.Vendor[0].Code1099ID = "Misc Income";}
        if(dsVend.Vendor[0].TINType == "") 
          {dsVend.Vendor[0].TINType = "0";}
        dsVend.Vendor[0].RowMod = "U";
        svc.ChangeVendPayMethod(5, ref dsVend);               
        svc.Update(ref dsVend );
      }
         
}

The error:

Server Side Exception

BPM runtime caught an unexpected exception of 'NullReferenceException' type.
See more info in the Inner Exception section of Exception Details.

Exception caught in: Epicor.ServiceModel

Error Detail 
============
Correlation ID:  786ae2b4-16a9-489f-bb8a-7d008518ae14
Description:  BPM runtime caught an unexpected exception of 'NullReferenceException' type.
See more info in the Inner Exception section of Exception Details.
Program:  Erp.Services.BO.Vendor.dll
Method:  VendorBeforeUpdate
Line Number:  4295
Column Number:  13
Original Exception Type:  NullReferenceException

Client Stack Trace 
==================
   at Epicor.ServiceModel.Channels.ImplBase`1.ShouldRethrowNonRetryableException(Exception ex, DataSet[] dataSets)
   at Ice.Proxy.BO.DynamicQueryImpl.RunCustomAction(DynamicQueryDataSet queryDS, String actionID, DataSet queryResultDataset)
   at Ice.Adapters.DynamicQueryAdapter.<>c__DisplayClass43_0.<RunCustomAction>b__0(DataSet datasetToSend)
   at Ice.Adapters.DynamicQueryAdapter.ProcessUbaqMethod(String methodName, DataSet updatedDS, Func`2 methodExecutor, Boolean refreshQueryResultsDataset)
   at Ice.Adapters.DynamicQueryAdapter.RunCustomAction(DynamicQueryDataSet queryDS, String actionId, DataSet updatedDS, Boolean refreshQueryResultsDataset)
   at Ice.UI.App.BAQDesignerEntry.BAQTransaction.<>c__DisplayClass386_0.<CallRunCustom>b__0(Int32& rowReturned)
   at Ice.UI.App.BAQDesignerEntry.Forms.BAQDiagramForm.ShowQueryResults(DataSet dsResults, getQueryResult getResults, ReportAdditionalInfo additionalInfo)
   at Ice.UI.App.BAQDesignerEntry.BAQTransaction.CallRunCustom()

Inner Exception 
===============
Object reference not set to an instance of an object.



There are a few BOs in the trace that I am not sure if I need here to update the 1099 and TINType. They are: OnChangeFormType() and OnChangeCode1099(). Do I need to pull in these BOs for this to work?

I updated again. I think this code closely represents what I want to accomplish. But I am still getting server side error. I think it is on the rowmod=“U” line, because if I comment that out, then I don’t get an error.


foreach (var ttResults_iterator in (from ttResults_Row in ttResults select ttResults_Row)) // for every line in the BAQ results do this stuff...
{
       
    using (Erp.Contracts.VendorSvcContract svc = Ice.Assemblies.ServiceRenderer.GetService<Erp.Contracts.VendorSvcContract>(Db))
      {
        var dsVend = svc.GetByID(ttResults_iterator.Vendor_VendorNum);
       
        
        if((dsVend.Vendor[0].Print1099 == true) && (dsVend.Vendor[0].TINType == ""))
        {
         dsVend.Vendor[0].Reporting1099Name = dsVend.Vendor[0].Name;
         dsVend.Vendor[0].Code1099ID = "Misc Income";
         dsVend.Vendor[0].FormTypeID = "1099 Misc In";
         dsVend.Vendor[0].TINType = "0";
        }  
       // dsVend.Vendor[0].RowMod = "U";
        
        svc.ChangeVendPayMethod(5, ref dsVend);               
        svc.Update(ref dsVend );
      }
         
}

I noticed that my record counts have been going down. So at some point in my attempts, some of the records are being updated correctly. However, I can’t figure out why this is still stuck at the server error. If I take out the rowmod line, then I don’t get an error, and the action completes, but the records don’t get updated. If I leave the rowmod line in, the server error comes up every time.

With the rowmod line in, try running it again and then check the server event logs, there may be more error detail there. My guess is that there is some other data issue.

To answer your other question, yes you should call the OnChange methods you listed, probably after setting the fields and before calling the ChangeVendPayMethod method.

Another thing to test would be to filter your dashboard for now to several vendors you know have no other data issues ( like Print1099 = false, etc.). Also try changing the pay method in the UI for those vendors and see if you get any other errors.

Thanks again for your help! Unfortunately I can’t check the server logs. I have to send a request to Epicor support to check them. Usually this is too much of a pain to bother with. I will keep playing with the BOs and see if I can get it going. I can tell a bunch have updated now. There’s just something holding up the rest.
Thanks!
Nate

Aw at one point you could through the browser, once you find out the File Format.

Some logs are available through the Service File Download app. Choose Company as the Directory Type and choose from the three folders.

I was able to download one log, a “pelog.txt”. Its just a blank file. I will run a few more tests and check back here to see if I get anything in the logs. Do I have to turn on tracing or logging somewhere?

EDIT: I ran the custom action again with rowmod=u to generate the server side exception. This did not generate a log file, or update the existing log file. I tried again with tracing turned on. The trace didn’t show anything useful, and the log file is still blank.

foreach (var ttResults_iterator in (from ttResults_Row in ttResults select ttResults_Row)) // for every line in the BAQ results do this stuff...
{    
    using (Erp.Contracts.VendorSvcContract svc = Ice.Assemblies.ServiceRenderer.GetService<Erp.Contracts.VendorSvcContract>(Db))
      {
        var dsVend = svc.GetByID(ttResults_iterator.Vendor_VendorNum);

            string msg = String.Format("VendorRowCount:{0}", dsVend.Vendor.Count().ToString());
          
            foreach ( var vendorRow in dsVend.Vendor )
            {
              msg += System.Environment.NewLine + String.Format("Vendor:{0} PMUID:{1} RowMod:{2}", vendorRow.VendorNum.ToString(), vendorRow.PMUID.ToString(), vendorRow.RowMod);
            }
          
          this.PublishInfoMessage(msg, Ice.Common.BusinessObjectMessageType.Information, Ice.Bpm.InfoMessageDisplayMode.Individual, "", "" );


        if((dsVend.Vendor[0].Print1099 == true) && (dsVend.Vendor[0].TINType == ""))
        {
        dsVend.Vendor[0].Reporting1099Name = ttResults_iterator.Vendor_Name;
        dsVend.Vendor[0].Code1099ID = "Misc Income";
        dsVend.Vendor[0].FormTypeID = "1099 Misc In";
        dsVend.Vendor[0].TINType = "0";
        }  
        dsVend.Vendor[0].RowMod = "U";
        
        svc.ChangeVendPayMethod(5, ref dsVend);               
        svc.Update(ref dsVend );
      }   
}

This code compiles without error but still generates the server side exception I posted above.

Does the Vendor[0].RowMod not exist? I feel like something must be wrong with this line.

I got something that seems to work at least some of the time. There must be something wrong with a few records in my vendor table. As the custom action proceeds through changing the payment method for each vendor, sometimes it still errors out with the error above. However most of the records get updated in between. Once the action errors out, I just manually open the next vendor in the list, and manually change the pay methods and save in Supplier Maintenance. Then I jump back to the BAQ and rerun the query and action.

I think the main change I made was to define dsVend as a tableset. I also switched from GetByID, to GetByVendID.

foreach (var ttResults_iterator in (from ttResults_Row in ttResults select ttResults_Row)) // for every line in the BAQ results do this stuff...
{    
    using (Erp.Contracts.VendorSvcContract svc = Ice.Assemblies.ServiceRenderer.GetService<Erp.Contracts.VendorSvcContract>(Db))
      {
            VendorTableset dsVend = new VendorTableset(); 
        
            dsVend = svc.GetByVendID(ttResults_iterator.Vendor_VendorID);

 
        dsVend.Vendor[0].RowMod = "U";
        
        svc.ChangeVendPayMethod(5, ref dsVend);               
        svc.Update(ref dsVend );
      }   
}

While this isn’t a perfect solution, it does certainly help update all the vendor pay methods, even if I have to intervene manually a little bit.
FindNoPayMethods.baq (51.0 KB)

Thanks everyone for your help!!
Nate

EDIT: After I cleaned up a few vendor records in my live epicor, I ran this and all 2000+ vendors were updated successfully!

Just to top it off, I setup a little post-processing directive to automatically set the Payment Method for new vendors. Just one less thing for our end users to worry about. I used an update table by query, and set the query to filter the ttVendor table for RowMod=“A”. Then, I just set the PMUID and RowMod to “U”. It seems to work like a charm!