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
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:
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
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);
The first one seems to need only the CMTs, when I used CMTs.CMOrderHed I got this error:
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: