Adding Business Object Calls into Custom C# Method Directive code

,

Ladies & Gentlemen,
Epicor E70.2.700 Public cloud here and I have a requirement in a Pre-Processing Method Directive to add a record into the UD Codes filewith a specific CodetypeID and CodeID if it doesn’t exist already. getting data from the ttable isn’t a problem using code similar to the following:

foreach(var MyUDCodes in 
      (from ThisUDCodes in Db.UDCodes.With(LockHint.UpdLock)
        where ThisUDCodes.Company == Session.CompanyID 
          && ThisUDCodes.CodeTypeID == "NEXT" 
          && ThisUDCodes.CodeID == "CUST_AUT"
      select ThisUDCodes))  

Obviously this reads the database table directly and works fine.
However, I need to know how to add a specific entry into the table if it isn’t already there and I guess don’t want to be updating the table directly so I am looking at the Business Object to add records as required to avoid attempting to update the tables directly with inherent locking problems etc…

I have successfully used the Ice.BO.UserCodesSVc Business Object using Postman and I can successfully add records using the POST operation as well as retrieve records using the GET procedure but I have no idea on how I can incorporate the BO call to retrieve a record, test if it is there and then add it in if it doesn’t exist into my custom C# Method directive code using the BO.

Any help would be most welcome.

I have now virtually solved my problem in the original post. All I am missing is the ability to create an Adapter for the UDCodes tablein the C# custom code. The issue I have is which References I need to add and/or using references in the code so as to create the adapter.

Any help please?

Since you are doing a method directive BPM, I would try to just use the “Invoke BO Method” widget to make the BO calls you’re after.

1 Like

Adam, thanks… I only just discovered that and I am trying to sort out what parameters I need to add a record into the Ice.UserCodes.GetNewUDCodes BO and obviously how to set up the parameters in the Custom code which will call the InvokeBO Method - Always assuming that the Ice.UserCodes.GetNewUDCodes BO is the correct one of course as that is the only one which seems to mention NewUDCodes.

Is there a good place to find the documentation on Business Objects as the only reference is from the Rest API which I have used, but it isn’t required in this instance?

To confirm you are looking at the right BO/method, you can run a trace on the regular process a user goes through to add a new user code in User Code Maintenance. I ran the trace, it looks like you are looking at the right BO/method to me. I also see UserCode.GetNewUDCodeType gets called if the code type hasn’t been defined.

The BL Tester is the best place I can think of to investigate BO methods and what parameters they require:

You can use this tester to test BO calls, and you can also pass data from one BO call to another, mimicking how it could work in Code or multiple widgets.

If you start setting up a “Invoke BO Widget” in a method directive, it will also show what parameters / outputs are available to each BO method (after you select it).

1 Like

Adam, unfortunately on Public Cloud 10.2.700 so can’t use the BL Tester but thanks for letting me know about it anyhow. It may be useful in the future of we go On-Prem.

I must admit though I am struggling to find out how to create a UserCodesTableset to populate and then send to the Invoke BO Method. If you or anyone else can shed light onto what references and using details as well as the code I need to create the tableset I would be very thankful! I have trawled this usergroup and and all the Manuals I can lay my hands on with no success.

Here’s a snippet of something similar I did (albeit with a completely different BO).

      var bo = Ice.Assemblies.ServiceRenderer.GetService<JobStatusSvcContract>(Db);
      var ds = bo.GetByID(j.JobNum);
      
      //create Before image 
      var origRow = ds.JobHead.NewRow();
      BufferCopy.Copy(ds.JobHead[0], origRow);
      ds.JobHead.Add(origRow);
      
      //update record
      string jobNum = j.JobNum;
      ds.JobHead[0].ToFirm = true;
      ds.JobHead[0].RowMod = "U";
      bo.ChangeJobHeadFirm(true,jobNum, ref ds);

      ds.JobHead[0].RowMod = "U";
      ds.JobHead[0].JobFirm = true;
      ds.JobHead[0].ExtUpdated = true;
      bo.MassUpdate(ref ds);

This was inside a transaction scope and with logic deciding when to invoke it to firm jobs, but it’s basically the pattern I use for invoking business object. Search this forum for “Trace Differ” for a great tool to go through trace files, and yes, the BLTester is the way to go to figure out what to call.

Caveat: don’t use “ds” as a dataset name as in some contexts it is already used by Epicor as the name of the BPM’s dataset.

Edit - just saw your note about BL Tester, sorry.

1 Like

Hi Dave,

You can use the BL Tester with the public cloud. You may have to download the 10.2.700 release from EpicWeb to extract it. I think you can also file a ticket to have Support send it to you.

The only issue I’ve had was an SSPI error and EpicCare said to use the IP Address.

Mark W.

Thanks Mark …as usual, many thanks.

1 Like

Steve, trying to use your coding method I am trying to add a record into the UDCodes table with a specific CodeType (in this case “NEXT” and a CodeID of “CUST_XXX” where the XXX is defined from the Customer Name. This allows the table to be used to classify a Customer’s ID from a 3 digit identifier - for example IPN and as sequential number taken from the lookup in the UDCodes table from the description field (See “CUST_IPN” record with 6 in the description field. This description field is updated by 1 for the next Customer that is allocated the identifier “IPN”.followed with the number 006 making up a Customer Id of IPN006 with the 006 in the UDCodes “CUST_IPN” record being updated to be 7.

If the records in the UDCodes table exist then my procedure runs faultlessly but when an new identifier not in the table is specified. However I cannot for the life of me seem to add a new record into the UDCodes table. Here is the code I am using which is in line C#. I have tried to call the BO Object GetNewCodes method using the Widget but this also doesn’t seem to work.

     // We need to create another UD Code record
    nNextCustNum = 1;
    cShort_Id = "IPN";
    cPrefix = "CUST_";

    var bo=Ice.Assemblies.ServiceRenderer.GetService<UserCodesSvcContract>(Db);
    var dsCodes_Updated = bo.GetByID("NEXT");

    var oNewRow = dsCodes_Updated.UDCodes.NewRow();
    dsCodes_Updated.UDCodes.Add(oNewRow);

    dsCodes_Updated.UDCodes[0].CodeTypeID="NEXT";
    dsCodes_Updated.UDCodes[0].CodeID = cPrefix+cShort_Id;
    dsCodes_Updated.UDCodes[0].CodeDesc = string.Format("{0}",nNextCustNum+1);
  
    // Add the new UDCodes record into the table
    bo.Update(ref dsCodes_Updated);

Unfortunately the above code compiles syntax wise fine but refuses to generate a new UDCode “CUST_IPN” with a description contents as “1”

If you type BO. (include the dot) and then press ctrl+space and wait a moment, it should bring up a list of available methods. Maybe there’s another method specifically for adding new?

Another possibility, I don’t know about this case, but I know if you’re creating a sales order programmatically, you have to set OrderNum=0 which tells Epicor to generate the next one. Maybe there’s something like that?

Have you tried to set RowMod = “A” on the new record prior to the call to Update?

1 Like

Gary,
No idea what this does and how you know it but that worked like a charm!

Problem Solved!

Thank you immensely!

Hi Dave,
In brief you set RowMod based on what you’re trying to do -

“A” = Add a record
“U” = Update a record
“D” = Delete a record

NB if you’re working in with “tt” tables there is a 4th value of “” (blank) - you’ll find these records as a pair with “U” records where the “” is a copy the original record prior to the update and the “U” is the updated record.

Regards,
Gary

1 Like

Said all of us at one point or another!

2 Likes