Overriding Credit-Hold using BPM

I did not expect it to be easy, at least I’ve made progress with your help.
I will try this and update this thread.
Thanks again for your help !

1 Like

It worked :slight_smile:
Set the BPM Context data → Company and OrderNum in the Pre-Processing

Then in second one after, in the Post-Processing used the context fields and got the data from Db and the rest of the code is the same:

string company = "";
int ordernum = 0;
decimal orderamount = 0;
bool creditPaymentReceived = false;
int custnum = 0;
string BTcustid = "";
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");


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

company =    callContextBpmData.Character01;     
ordernum =    (int)callContextBpmData.Number01; 
              
foreach (var OrderHedRow in (from OrderHed_Row in Db.OrderHed
              where  OrderHed_Row.Company == company && OrderHed_Row.OrderNum == ordernum 
              select OrderHed_Row))
                        {
                          
            
             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;
                BTcustid = CustomerRow.CustID;
              }  
            
            
            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(BTcustid);
           
           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)
            {

            
            
            
            
            
            
            
            
                                        
                        

              

}

Thank you @klincecum
You are a life-saver.
You deserve a big thank-you.

:heart: :heart: :heart: :heart: :heart: :heart: :heart: :heart: :heart: :heart: :heart: :heart: :heart: :heart: :heart: :heart: :heart: :heart: :heart: :heart: :heart: :heart: :heart: :heart: :heart: :heart: :heart: :heart: :heart: :heart:

2 Likes