PO Duplicate in So should be warning message to Continue or clear the SO

Hi,
I want to create BPM where want warning if PO number is duplicate in SO and it should get the warning Continue or clear the SO. I created custom code but getting error. Please find below my code.

(// Get CustNum & PONum from temporary ttOrderHed table;
var currentOrder = ttOrderHed.Where(o => o.Added() || o.Updated()).FirstOrDefault();
if (currentOrder == null || string.IsNullOrEmpty(currentOrder.PONum))
    return;
// Check for existing orders with the same Customer and PO number
var duplicateOrder = Db.OrderHed.Where(
    oh => oh.Company == currentOrder.Company &&
    oh.CustNum == currentOrder.CustNum &&
    oh.PONum == currentOrder.PONum &&
    oh.OrderNum != currentOrder.OrderNum).FirstOrDefault();
// If a duplicate is found, show the BPM form
if (duplicateOrder != null)
{
    // Create and show a BPM form
    // The form has a message and two buttons: "OK" and "Clear"
    string message = "Duplicate PO Number detected. Do you want to proceed or clear the field?";
    string buttonSelected = Ice.Bpm.Controls.ShowMessageBox(message, "Duplicate PO", "OK", "Clear");

    // Handle user's choice
    switch (buttonSelected)
    {
        case "OK":
            // Proceed with the save. No action needed here.
            break;
        case "Clear":
            // Clear the PO number field
            currentOrder.PONum = string.Empty;
            break;
        default:
            // The user closed the box without selecting an option.
            // Throw an exception to stop the process.
            throw new Ice.BLException("Save cancelled.");
    }
})

I am getting error - Ice.Bpm.Control.Controls - controls does not exisit
Regards,
Sudesh H Shetty

That property doesn’t exist (just like the error says) where did you get that code from?

Hi,
I got it from one of my friend.

Regards,
Sudesh H Shetty

Yeah, you’ll have to ask your friend then.

1 Like

Is this code which is shared is totally wrong or only which I am getting error when execute

I don’t know of anything in a BPM other that a BPM data form that can present buttons and take a user input back. Which is really why I went to see if it existed, because it would be super helpful if it was.

So as far as my knowledge goes, this code is “Totally wrong”.

Although it’s possible that there is something that exists that I don’t know about.

Can I ask, Did you have chat GPT generate the code for you? Cause if you did, and you don’t know what the code is doing, you probably shouldn’t do that.

2 Likes

Hi,
I previously created one BPM with the below code but it is giving warning but saves the data. Please find below code:

Erp.Tables.OrderHed OrderHed;

foreach(var item in ttOrderHed.Where(row => row.Added()||row.Updated()))
{
  if(item.PONum != null)
  {
    var Order = (from row in Db.OrderHed where row.Company == Session.CompanyID && row.PONum == item.PONum select row ).FirstOrDefault();
    if(Order != null)
    {
      string message = "PO#: '" + item.PONum + "' already exists on order " + Order.OrderNum;
      this.PublishInfoMessage(message, Ice.Common.BusinessObjectMessageType.Warning, Ice.Bpm.InfoMessageDisplayMode.Individual, "", "");
    }
  }
}

This code does nothing to cancel the transaction. It looks to see if the PO exists and, if so, displays the message. I think you’ll want to steal some of the code from above to exclude the current sales order or you’ll never be able to update that order.

Like @Banderson said, people use a BPMDataForm to prompt the user for a response. You would take that response and conditionally save or cancel the update.

If you ALWAYS want to prevent a duplication PO, you can set it by customer:

1 Like

Thank you
I already suggested this to business but they don’t want hard stop. They want just warning so it allow to continue or clear

1 Like

We always check but infrequently we do allow a duplicate PO because the customer changed the PO and we want a new sales order. Up to now, we toggle the flag, add the order, and then toggle it back. But if the frequency is high enough, we will probably want to do the same. You may also want to display the other order and the amount to help the user in determining if it is indeed a duplicate.