Use BO in Function Custom Code

Anyone figure out how to call a BO in function custom code, GetService does not work… problem I am running into is that Db does not exist in this context like in a BPM. Reason I am doing this is to call a BAQ and process the results

Ice.Assemblies.ServiceRenderer.GetService

Here’s an example on how to run the BAQ and process the output as needed.

Epicor Functions and BAQs - ERP 10 - Epicor User Help Forum (epiusers.help)

2 Likes

Need to reference the contract of course, but use the CallService to instantiate the BO from a function code

//Get New Quote Dtl
        this.CallService<Erp.Contracts.QuoteSvcContract>(qs =>{
        qs.GetNewQuoteDtl(ref tsQuote, quoteNum);
3 Likes

Thank you @Mark_Wonsil and @Aaron_Moreng this will get me moving again

Hi everyone,
I understand this topic is kinda old.
I need to update Credit Hold status of an order.
Could you please provide some hints for doing so through custom code and BO call?
I used Epicor Trace Parser and found that this is the BO that gets called:

Many thanks in advance

The methods you are interested in are:

CreditManager.ChangeOrderCreditHold
CreditManager.UpdateCMOrderHed

You need to pull the CMOrderHedDataSet for the order,
change the
CreditHold field to False
CreditOverride field to true
CreditOverrideLimit to the Order Total

call CreditManager.ChangeOrderCreditHold with that dataset

take the returned dataset
and pass it and the customer number to CreditManager.UpdateCMOrderHed

1 Like

Hi @klincecum ,

Thanks a lot for your response!
It makes a lot of sense.
I attempted to do so like this:

var CMsvc = Ice.Assemblies.ServiceRenderer.GetService<Erp.Contracts.SalesOrderSvcContract>(Db);
Erp.Tablesets.CMOrderHedTableset  CMTs = new Erp.Tablesets.CMOrderHedTableset();
CMTs = CMsvc.GetByID(ordernum);
            
CMTs.CMCustomer[0].CreditHold = false;
CMTs.CMCustomer[0].ChangeOrderCreditHold  = false;
CMTs.CMCustomer[0].CreditOverrideTime = "1234";
            
CMsvc.Update(ref CMTs);

But I get these errors, could you kindly help me find where I am making the mistake?

These are the references that I have used:
image

  var CMsvc = Ice.Assemblies.ServiceRenderer.GetService<Erp.Contracts.CreditManagerSvcContract>(Db);
  Erp.Tablesets.CMOrderHedTableset CMTs = new Erp.Tablesets.CMOrderHedTableset();
  
    string custNum = "1227";
    int orderNum = 12345;
  
    CMTs = CMsvc.GetOrders(custNum);
  
    CMOrderHedRow ordersToRemoveHoldFrom = (from ordersOnHold in CMTs.CMOrderHed
                                      where
                                          ordersOnHold.OrderNum == orderNum
                                      select
                                          ordersOnHold).FirstOrDefault();
  
    ordersToRemoveHoldFrom.CreditHold = false;
    ordersToRemoveHoldFrom.CreditOverride = true;
    ordersToRemoveHoldFrom.CreditOverrideLimit = ordersToRemoveHoldFrom.OrderTotal;

That should get you closer.

1 Like

This was very informative.
I really appreciate that you used my terminology.
I already have retrieved the CustNum in previous part of my code so that is no problem and since it is an int, I have converted it to a string to work with your code.

I am new to this so please bear with me if I sound stupid. It seems that we retrieved the whole dataset, then we filtered the record that we want, and then we stored the record in a CMOrderHedRow element and then modify the values as we please.
That makes 100% sense and I understand that.

Now I am for sure 1000 steps closer, the problem is that in all examples, I have to use an update method, as you previoously stated before, I should use this:
CreditManager.UpdateCMOrderHed

When I use this:
CMsvc.UpdateCMOrderHed(ref ordersToRemoveHoldFrom);
I get this error:
There is no argument given that corresponds to the required formal parameter ‘ds’ of ‘CreditManagerSvcContract.UpdateCMOrderHed(int, ref CMOrderHedTableset)’

Which basically means the parameter that I am passing is not in correct format. So it seems I have to somehow convert the ordersToRemoveHoldFrom which is in CMOrderHedRow format to CMOrderHedTableset fromat.
I am not sure how to do this.
One thing that comes to my mind to skip the use of CMOrderHedRow is to iterate in CMTs and modify the values where the criteria is met.
Something like this:

foreach (var CMOrderHedRow in (from CMOrderHed_Row in CMTs.CMOrderHed
                            where CMOrderHed_Row.OrderNum == ordernum
                            select CMOrderHed_Row))
                            {
                                CMOrderHedRow.CreditHold = true;
                                CMOrderHedRow.CreditOverride = true;
                                CMOrderHedRow.CreditOverrideLimit = CMOrderHedRow.OrderTotal;
                                
                            }

And then get the result set that is still CMTs and use it in Update.
Would this work? I still get an error.
This is my full code in one place:

var CMsvc = Ice.Assemblies.ServiceRenderer.GetService<Erp.Contracts.CreditManagerSvcContract>(Db);
Erp.Tablesets.CMOrderHedTableset CMTs = new Erp.Tablesets.CMOrderHedTableset();
  
CMTs = CMsvc.GetOrders(custnum.ToString());
 
CMOrderHedRow ordersToRemoveHoldFrom = (from ordersOnHold in CMTs.CMOrderHed   where ordersOnHold.OrderNum == ordernum select ordersOnHold).FirstOrDefault();
                              
ordersToRemoveHoldFrom.CreditHold = false;
ordersToRemoveHoldFrom.CreditOverride = true;
ordersToRemoveHoldFrom.CreditOverrideLimit = ordersToRemoveHoldFrom.OrderTotal;
  
foreach (var CMOrderHedRow in (from CMOrderHed_Row in CMTs.CMOrderHed
                where CMOrderHed_Row.OrderNum == ordernum
                select CMOrderHed_Row))
                {
                    CMOrderHedRow.CreditHold = true;
                    CMOrderHedRow.CreditOverride = true;
                    CMOrderHedRow.CreditOverrideLimit = CMOrderHedRow.OrderTotal;
                    
                }     
                
CMsvc.UpdateCMOrderHed(CMTs.CMOrderHed);

And this is the error:

It’s the same thing.

You are modifying a row inside this dataset: ordersToRemoveHoldFrom is just a reference to the row
inside CMTs.CMOrderHed

set your rowmod to “U” on it

call

CreditManager.ChangeOrderCreditHold(ref CMTs.CMOrderHed);

then

CreditManager.UpdateCMOrderHed

1 Like

The first one seems to need only the CMTs, when I used CMTs.CMOrderHed I got this error:
image

After changing that to CMTs, it gets fixed, so now the Update method, The only thing that comes to my mind is to use again CMTs, or CMTs.CMOrderHed, or just leave it empty, and in all three I get error:

But I can smell the victory with your help now :slight_smile:

1 Like

you are missing the customer number.

CMsvc.ChangeOrderHed( custNumHere!, ref CMTs);

1 Like

Perfect!
My code compiles correctly now.
This is great, now I get to test this.
I will update this thread with results later.

You are a legend @klincecum :smiling_face_with_three_hearts:

Next time make your own thread so I can get the credit :rofl: