Overriding Credit-Hold using BPM

Hi Epicor community,
We set every Order on Credit-hold upon its creation.
Now we would like to override that credit-hold when a user checks a checkbox.
It is not as straightforward as it sounds but to explain it in a very simple format, when the checkbox is checked, a series of evaluations (If statements if you will) will examine the Order characteristics and if a certain criteria is met in each conditional statement, we would like to perform certain operations, one of which is overriding the credit-hold.

My question is this:
What is the best practice for overriding a credit-hold using BPM provided that I need to perform certain evaluations using Custom Code ?
Context: I am aware that OrderHed table holds 5 columns that are relevant to credit-hold status

[CreditOverride]
[CreditOverrideUserID]
[CreditOverrideDate]
[CreditOverrideTime]
[CreditOverrideLimit]

I was thinking maybe an easy idea is to just modify these through the Custom Code, however I am not sure if Overriding the Credit using the application itself only involves these columns and possibly impacts the database in other areas as well, so decided to ask you about this.

Many thanks in advance
Shizar

Use the CustomerCredit BO and set the few fields needed.

2 Likes

Thank you very much @Jason_Woods
Any chance you can refer me to a working example where it demonstrates how to use BOs in Custom Code?
I am not familiar with that.

Many thanks

I don’t have anything handy, but if you run a trace from the Customer Credit Manager, you will see what calls are being made and what data is being changed. I recommend the Epicor Trace Differ (Trace Helper Utility for Epicor ERP 10) to see how the data interacts.
Then, there are lots of examples of how to call BOs here on the forum.

1 Like

You ever get this working? I lost the other thread lol.

1 Like

Hi @klincecum
I had created this thread previously and since I did not get any response I desperately looked for similar issues.
The code compiled well, there is still an issue. I get an error and the error is due to the section that I wrote with your help (To be honest you helped and wrote all of it, I cannot take any credit for that) which I am very grateful for.

This is the complete code that I have:

string company = "";
int ordernum = 0;
decimal orderamount = 0;
bool creditPaymentReceived = false;
int custnum = 0;
int BTcustnum = 0;
bool bypassCreditCheckUnder10k = false;
bool IsWarranty = false;
string CustomerPaymentTerm = "";
bool NoOverdueInvoice = true;
bool shouldAutoRelease = false;
DateTime today = DateTime.Now;


    
    
    this.PublishInfoMessage("checkpoint00", Ice.Common.BusinessObjectMessageType.Information, Ice.Bpm.InfoMessageDisplayMode.Individual, "FirstVar","SecondVar");
if(ttOrderHed.Any())

{

this.PublishInfoMessage("checkpoint01", Ice.Common.BusinessObjectMessageType.Information, Ice.Bpm.InfoMessageDisplayMode.Individual, "FirstVar","SecondVar");


              
foreach (var OrderHedRow in ttOrderHed)
                        {
                          
            company =  OrderHedRow.Company;        
            ordernum = OrderHedRow.OrderNum;
             this.PublishInfoMessage("OrderNum is -->"+ordernum.ToString(), Ice.Common.BusinessObjectMessageType.Information, Ice.Bpm.InfoMessageDisplayMode.Individual, "FirstVar","SecondVar");
             
            orderamount = OrderHedRow.TotalCharges-OrderHedRow.TotalDiscount+OrderHedRow.TotalTax+OrderHedRow.TotalMisc;
            creditPaymentReceived = (bool)OrderHedRow["CreditPaymentReceived_c"];
            custnum = OrderHedRow.CustNum;
            BTcustnum = OrderHedRow.BTCustNum;
            IsWarranty = (bool)OrderHedRow["IsWarranty_c"];
            
            foreach (var CustomerRow in (from Customer_Row in Db.Customer
              where  Customer_Row.Company == company && Customer_Row.CustNum == BTcustnum 
              select Customer_Row))
              {
              this.PublishInfoMessage("Customer Name -->"+CustomerRow.Name, Ice.Common.BusinessObjectMessageType.Information, Ice.Bpm.InfoMessageDisplayMode.Individual, "FirstVar","SecondVar");
                bypassCreditCheckUnder10k = false;
                CustomerPaymentTerm = CustomerRow.TermsCode;
              }  
            
            
            if(orderamount<1 && orderamount >-1)
            {
              //Auto Release --> No Charge Order
              this.PublishInfoMessage("Auto Release --> No Charge Order", Ice.Common.BusinessObjectMessageType.Information, Ice.Bpm.InfoMessageDisplayMode.Individual, "FirstVar","SecondVar");
              shouldAutoRelease = true;
              
            }
            else if(IsWarranty)
            {
              //Auto Release --> Warranty
              this.PublishInfoMessage("Auto Release --> Warranty", Ice.Common.BusinessObjectMessageType.Information, Ice.Bpm.InfoMessageDisplayMode.Individual, "FirstVar","SecondVar");
              shouldAutoRelease = true;
            }
            
            else if(creditPaymentReceived && orderamount<=10000)
            {
            
              //Auto Release --> Credit Card Payment Received
              this.PublishInfoMessage("Auto Release --> Credit Card Payment Received", Ice.Common.BusinessObjectMessageType.Information, Ice.Bpm.InfoMessageDisplayMode.Individual, "FirstVar","SecondVar");
              shouldAutoRelease = true;
            }
            
            else if(!creditPaymentReceived)
            {
            
              //Auto Release --> No Credit Payment
              this.PublishInfoMessage("Auto Release --> No Credit Payment", Ice.Common.BusinessObjectMessageType.Information, Ice.Bpm.InfoMessageDisplayMode.Individual, "FirstVar","SecondVar");
              
                    if(CustomerPaymentTerm.Equals("NET30"))
                    {
                    
                      //Auto Release --> NET30 and no overdue
                      this.PublishInfoMessage("Auto Release --> NET30 and no overdue", Ice.Common.BusinessObjectMessageType.Information, Ice.Bpm.InfoMessageDisplayMode.Individual, "FirstVar","SecondVar");
                      shouldAutoRelease = true;
                          foreach (var InvcHeadRow in (from InvcHead_Row in Db.InvcHead
                            where  InvcHead_Row.Company == company && InvcHead_Row.CustNum == BTcustnum 
                            select InvcHead_Row))
                            {
                                if(InvcHeadRow.InvoiceBal >0 && InvcHeadRow.DueDate>today)
                                {
                                  shouldAutoRelease = false;
                                }                              
                            }                      
                    }              
            }
            
            else if(bypassCreditCheckUnder10k && orderamount<=10000)
            {
            
              //Auto Release --> Bypass and under 10k
              this.PublishInfoMessage("Auto Release --> Bypass and under 10k", Ice.Common.BusinessObjectMessageType.Information, Ice.Bpm.InfoMessageDisplayMode.Individual, "FirstVar","SecondVar");
              shouldAutoRelease = true;
            }
            
            
            }
            if(shouldAutoRelease)
            {
            
            this.PublishInfoMessage("shouldAutoRelease", Ice.Common.BusinessObjectMessageType.Information, Ice.Bpm.InfoMessageDisplayMode.Individual, "FirstVar","SecondVar");
            
            
            
            
           var CMsvc = Ice.Assemblies.ServiceRenderer.GetService<Erp.Contracts.CreditManagerSvcContract>(Db);
           Erp.Tablesets.CMOrderHedTableset CMTs = new Erp.Tablesets.CMOrderHedTableset();
  
           CMTs = CMsvc.GetOrders(BTcustnum.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;
           ordersToRemoveHoldFrom.RowMod="U";
           
          CMsvc.ChangeOrderCreditHold(ref CMTs);
          CMsvc.UpdateCMOrderHed(BTcustnum,ref CMTs );
           

            }
            else if(!shouldAutoRelease)
            {
            
          
            }
            
            
}

I have used this in SalesOrder Update function using Method Directive.
When I save any record, it throws this error right away, it does not even show the Message Box that I have in the custom code, without that section we added together the code runs fine.
Something seems to be Null for some reason…

This is also in case required. I hope this is not totally wrong :stuck_out_tongue:

I’d start commenting out sections of code from the bottom up and see where it fails.

It fails here

CMOrderHedRow ordersToRemoveHoldFrom = (from ordersOnHold in CMTs.CMOrderHed   where ordersOnHold.OrderNum == ordernum select ordersOnHold).FirstOrDefault();

You’re not matching on any orders, which means we didn’t pull something correctly,
or your orderNum is wrong

1 Like

Anyway, need a null check there :slight_smile:

CMTs = CMsvc.GetOrders("THIS IS SUPPOSED TO BE CUSTOMER ID NOT CUSTOMER NUMBER");
1 Like

Hey that worked!

The CustID thing resolved the issue that I had and now, of course, another issue, it says the row is being updated by another user.

This order is isolated and I am testing it on a Test environment so no other user is accessing it:
Is it due to changing the RowMod to “U” ?

image

Credit override is done though, no problem there
image

So basically what happens is that the Credit Override happens but then no other change takes place.
The process happens if a checkbox is checked and then the BPM kicks in, now that same checkbox that triggered the process does not remain checked after the error pops up…
:frowning:


Can you move it to post-processing, or would that mess up what you’re trying to do?

If you can’t move it to post, you might have to pull the orderhed data (from the bo) after the credit override, and compare it to the orderhed data you already have, and figure out what changed,
and then merge the datasets.

On post Processing does not work, better to say it seems the tt table is empty and no iteration happens.
I know how to trigger a Directive in Post-Processing using another directive in pre-processing
image

Now the question is, if I really have to do this, how would I pass the tt table to Post processing? Because I need the Order# for it to do the rest of the work.
Any ideas?
:slight_smile:

I wouldn’t think the dataset would be empty in post, but whatever.

You could pass the ordernum down in the callcontextbpmdata

Try this on your pre-processing one:

           
CMsvc.ChangeOrderCreditHold(ref CMTs);
CMsvc.UpdateCMOrderHed(BTcustnum, ref CMTs );
          
SalesOrderSvcContract salesBO = Ice.Assemblies.ServiceRenderer.GetService<SalesOrderSvcContract>(Db);
            
SalesOrderTableset salesOrder = salesBO.GetByID(ordernum);
            
dsHolder.Attach(salesOrder); 

It does not throw that error anymore but still does not keep the checkbox checked…
:frowning:

Aren’t you done at that point ?

No actually I need the checkbox to stay checked and that is the start of our process for credit checking.
Our sales team checks this checkbox, if it has to then it will be auto-released (you saw the logic in the code), if should not be auto-released then the Accounting department has their own dashboard that shows what is checked for credit checking (that checkbox) that its credit is not overridden.
Also one other issue with this is that if the user updates other pieces of information, for instance PO# or dates, those also won’t be saved.

I think you’re going to have to do it in post or trigger some other way.

When you save, you have changes.
Then the credit process also makes changes.
Now your changes are stale, even if we pull the updated record, the original changes need to be applied. Sounds complicated.

I’d pull that last bit of code I added out and move it to post if you can.