Script to only fire off Once

Before I start to write this script, is there a way to only allow a script to fire off once?  Background of the script I will create:  Need to populate the "SO DETAILS PURCHASEORDERNO" if blank with a "C" for all customers except 3 or 4, and only on lines with vendorno = "0001226".  However, I don't want the script to fire off every time an update is made to the SO, or if we delete the "C" in the POno field.  Basically, do not want the "C" to reappear if we delete it or for a legitimate POno to get overwritten by the "C".

  • Set a checkbox during your script run, and look at that value in the script filters.

  • Are you saying create an UDF checkbox to check off if the script fires then look at that checkbox first to see if the script needs to be run?

  • in reply to jland47

    Yes.  You can't stop an event from firing more than once, but you can save a value for "the script has already done its thing", and consider that value at the beginning of the script.

  • Why couldn't you use a Column-Post Validate event on the ItemCode field to fill the PO No. field for your conditions. It would only fire once per ItemCode and not when otherwise changing the line. 

  • in reply to connex

    Sorry but I am not following you on this code wise.

  • in reply to Kevin M

    I didn't create the UDF checkbox yet, have to get all 60 something users out before creating it so couldn't test.  This is a preliminary shot at the script.  The check box part to check the box off at the end of the script, I am not positive on.

    If oSession.CompanyCode = "ROI" then
    
    
    
    nPOno = ""
    
    nCustomerNo = ""
    
    nVendorno = ""
    
    sCCheckBox = ""
    
    
    
    rVal = oBusObj.GetValue("UDF_CCheckBox$", sCCheckBox)
    
    rval = oBusObj.GetValue("VendorNo$", nVendorNo)
    
    rVal = oBusObj.GetValue("CustomerNo$", nCustomerNo)
    
    rVal = oBusObj.GetValue("PurchaseOrderNo$", nPOno)
    
    
    
    	If sCCheckBox = "N" then
    
    
    
    		If nPOno = "" then
    
    
    
    			If nCustomerNo <> "2861000" or "2303006" then
    
    
    
    				If nVendorno = "0001226" then
    
    				rVal = oBusObj.SetValue("PurchaseOrderNo$", "C")
    
    				rVal = oBusObj.GetValue("UDF_CCheckBox$", sCCheckBox)
    
    					If sCCheckBox = "Y" then
    
    					rVal = oBusObj.SetValue("UDF_CCheckBox$", "Y")
    
    					End if
    
    				End if
    
    			End if	
    
    		End if
    
    	End if
    
    End if

  • in reply to jland47

    I said you can't prevent an event script from running more than once, but what connex is suggesting is using an event trigger (column post-validate on ItemCode) that naturally will only run once per line.  After you set a line's ItemCode, it never changes.

    If your business logic can be properly applied at that point, it is an excellent idea, and easier than the checkbox.

  • in reply to Kevin M

    I simplified the script without the checkbox and it populates the purchaseorderno field with the "C", however it does it no matter the customerno, so I have something wrong there.  Also curious on if I want the "C" value to be set only if a PO is not created, the column post-validate with this script fires off right after you enter the item code, I would think we would need it to look at the field after the record was written, gives the user a chance to create a PO if needed without going and deleting the "C".

    If oSession.CompanyCode = "ROI" then
    
    nCustomerNo = ""
    nVendorno = ""
    nPOno = ""
    
    rVal = oBusObj.GetValue("CustomerNo$", nCustomerNo)
    rVal = oBusObj.GetValue("VendorNo$", nVendorNo)
    rVal = oBusObj.GetValue("PurchaseOrderNo$", nPOno)
    
    	If nCustomerNo <> "2861000" or "2303006" then
    
    		If nVendorno = "0001226" then		
    
    			If nPOno = "" then			
    			rVal = oBusObj.SetValue("PurchaseOrderNo$", "C")
    			
    			End if	
    		End if
    	End if
    End if

  • in reply to jland47

    The business process is up to you.  For a pre-write event on the detail table you'd need the checkbox for control.

    Use oHeaderObj for your GetValue on CustomerNo (since it is a header field).

    Your filter on nCustomerNo is all wrong (and I'm surprised you don't get a VBScript syntax error).  Try something like this:

    variable <> "A" and variable <> "B"

  • in reply to connex

    Column Post Validate on ItemCode should work if on a version that allows selecting it (older versions didn't but I think 2020+ does in a detail script).

    A table Post Read event filtered by oBusObj.EditState = 2 also works and once the record is saved, the EditState will be equal to 1.

    Another event could be the Set Default Values one, I haven't used it much but it is supposed to run when default values are being set by the business object on new records.