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
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.
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:
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.