Order Creation Wizard PO Number

,

Hi everyone,
I am trying to implement a pre proc BPM on the OrderHed. Basically I want to warn the user if the PO number has been used already. I want to use the OrderHed.PONum here;


But if I enter an already used number I get no warning.
If I change the OrderHed.PONum here;
image
I get the warning.
All of our orders come from converted quotes which is why I want the check done in the Wizard.
The BPM code is a straight copy from here. Someone must have wanted to do the same thing but were happy to do it on the OrderUpdate.
Here is the code;

var ttOrderHedRow = (from ttOrderHed_Row in ttOrderHed
    where (ttOrderHed_Row.Added() || ttOrderHed_Row.Updated())
    select ttOrderHed_Row).FirstOrDefault();
if (ttOrderHedRow != null)

    var OrderHedRow = (from OrderHed_Row in Db.OrderHed
        where (OrderHed_Row.Company == ttOrderHedRow.Company && OrderHed_Row.CustNum == ttOrderHedRow.CustNum && OrderHed_Row.PONum == ttOrderHedRow.PONum 
            && OrderHed_Row.OrderNum != ttOrderHedRow.OrderNum) 
        select OrderHed_Row).FirstOrDefault();
    if (OrderHedRow != null)
    {

        this.PublishInfoMessage("WARNING - This PO has already been used on Sales Order " + OrderHedRow.OrderNum, 
            Ice.Common.BusinessObjectMessageType.Information, Ice.Bpm.InfoMessageDisplayMode.Individual, "SalesOrder", "CloseOrderLine");    
    }

Can anyone help me to get it working?

Best regards
Adrian.

First, have you check the Customer setup that prevents duplicate POs?
If that wont work, try sound a data directive so you capture all instances. This may slow Order Entry down slightly though.

Hi @Jason_Woods,
Yes but if we tick that box it is a hard stop. I am trying to get a one time warning at order creation time

Ah, then yes, either a Data Directive or you will need multiple Method Directives for each different way you create an Order.

We only create orders by converting quotes, but the BPM does not work on the Quote.CreateOrder. I think it may be to do with the wizard, but I don’t know for sure.

Hi @Adrian_Mepham
so do you want to validate Customer PO number on the Order BO/UI itself ? also do you want the PO validation to be across all customers or per each selected customer?

Hi @A.Baeisa, what I am trying to do is validate the PO at the Create Sales Order Wizard stage, most users enter the Customer PO here if it is not already populated from the quote.
At present, I am just looking at POs per customer

Ok mate, since that you want to trigger the validation process at this CallProcessScreen then the easiest way -in my opinion- is two BPM’s using widget will do that for you and no need for code, as per the following:

  1. Pre-Process method BPM on Quote BO CreateOrder method ( this is your trigger)

  2. Another In-Transaction Data BPM on Sales Order Head , it will check if there is at least one added record on this table [OrderHed], if yes it will assign two argument variables one to the ttOrderHed.PONum and the other one to ttOrderHed.CustomNum then it will check if there is any sales order within the database has these two criterias, if there is it will warn the user at this transaction.

HTH

2 Likes

Thanks @A.Baeisa!!,
That looks just what I am after. I will try and implement it this week. I am trying to get 10.2.400 ready for testing as well as other things…happy days!!
Thanks ever so much for this. I will let you know how it goes.

Best regards

Adrian.

no problem mate, i have found an issue on the ttOrderHedRow.CustNum and the ttOrderHedRow.PONum, so i have modified the variable assigning on the second BPM from these ttValues to CallContextBPMVariable :

and at this ProcessCallScreen form i.e. (CreateOrderWizardForm) i have capture these CallContextBPMVariables at before method call adapter, this is the customization code from the script editor:

// **************************************************
// Custom code for CreateOrderWizardForm
// Created: 29/08/2019 11:22:49
// **************************************************
using System;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Windows.Forms;
using Erp.Adapters;
using Erp.UI;
using Ice.Lib;
using Ice.Adapters;
using Ice.Lib.Customization;
using Ice.Lib.ExtendedProps;
using Ice.Lib.Framework;
using Ice.Lib.Searches;
using Ice.UI.FormFunctions;


public class Script
{
	// ** Wizard Insert Location - Do Not Remove 'Begin/End Wizard Added Module Level Variables' Comments! **
	// Begin Wizard Added Module Level Variables **

	private EpiBaseAdapter oTrans_adapter;//AB
	// End Wizard Added Module Level Variables **

	// Add Custom Module Level Variables Here **
private EpiDataView edvOrderHed;
	public void InitializeCustomCode()
	{
		// ** Wizard Insert Location - Do not delete 'Begin/End Wizard Added Variable Initialization' lines **
		// Begin Wizard Added Variable Initialization

	
		this.edvOrderHed = ((EpiDataView)(this.oTrans.EpiDataViews["OrderHed"]));//AB
		
		this.oTrans_adapter = ((EpiBaseAdapter)(this.csm.TransAdaptersHT["oTrans_adapter"]));//AB
		this.oTrans_adapter.BeforeAdapterMethod += new BeforeAdapterMethod(this.oTrans_adapter_BeforeAdapterMethod);//AB
		// End Wizard Added Variable Initialization

		// Begin Wizard Added Custom Method Calls

		// End Wizard Added Custom Method Calls
	}

	public void DestroyCustomCode()
	{
		// ** Wizard Insert Location - Do not delete 'Begin/End Wizard Added Object Disposal' lines **
		// Begin Wizard Added Object Disposal

		
		this.edvOrderHed = null;//AB
		this.oTrans_adapter.BeforeAdapterMethod -= new BeforeAdapterMethod(this.oTrans_adapter_BeforeAdapterMethod);//AB
		this.oTrans_adapter = null;//AB
		// End Wizard Added Object Disposal

		// Begin Custom Code Disposal

		// End Custom Code Disposal
	}

	

	private void oTrans_adapter_BeforeAdapterMethod(object sender, BeforeAdapterMethodArgs args)
	{
		switch (args.MethodName)
		{
			case "CreateOrder":
			System.Data.DataRow edvOrderHedRow = edvOrderHed.CurrentDataRow;	
				if (edvOrderHedRow!=null)
       	   {
				
				var vCustPONum = edvOrderHedRow["OrderPONum"]; 
				var vCustNum = edvOrderHedRow["CustNum"];
				EpiDataView edvCallContextBpmData = ((EpiDataView)(this.oTrans.EpiDataViews["CallContextBpmData"]));
				System.Data.DataRow edvCallContextBpmDataRow = edvCallContextBpmData.CurrentDataRow;
				if ((edvCallContextBpmDataRow != null))
				{
					edvCallContextBpmDataRow.BeginEdit();
					edvCallContextBpmDataRow["ShortChar05"] = vCustPONum;
					edvCallContextBpmDataRow["Number05"] = vCustNum;
					edvCallContextBpmDataRow.EndEdit();
				}
			//MessageBox.Show("Hi Ali"+"_"+vCustPONum+"_"+vCustNum);
				}
				break;
		}

	}
}

make sure that these callcontextBPM variables are not in used and clear them at the end of this BPM, please let me know how it goes