How to Flow a UDF from Sales Order Header to SO History Header Reliably

With identical UDF names in both tables, the original value set into the SO Header UDF via a ColumnPostValidate script from a standard field works to flow the value to SO History Header, but subsequent successful updates directly to that SO Header UDF from within the SO SalesOrder Bus object are not copied to the corresponding history UDF. Just the first. I see no explicit way to set this up because their appears to be no Data Source on which to define a SO History Header UDF from a SO Header.  The first copy must be auto programmed?

Advanced version 2020

  • 0

    Sales order header UDF should automatically update to sales order history header, along with other header fields.  It is done by the Write() method of the business object.  There is no need to set up data source.

  • 0 in reply to Natasha Chang

    Thank you for the reply! The 1st SetValue (the one that "sticks") is from a Column Post Validate script on FreightAmt, while the subsequent ones are done in a Pre-Totals event on the same SO business object, but after it has become a backorder having been invoiced since the successful CPV on FreightAmt.  A write wasn't necessary to get the 1st one to "stick", I always assumed that successful SetValue's on a Business Object before a the Post Write event would stick. I tried using a Write() after updating the header UDF and put it between Deactivate/Activate's in the header business object Pre-Totals event. No luck. I am wondering if it doesn't flow to history once the order becomes a back order.

  • 0 in reply to connex

    The Write() method will sync the sales order fields to sales order history for all order types.  You need to set the UDF value before Write() not Post Write.  Is your UDF value written to sales order header?

  • 0 in reply to Natasha Chang

    Thanks again! I'm doing this in a Pre-total event. The UDF is being updated in the sales order header, but not to the sales order history only the first time when it is a sales order and not a back order.

    nFreightAmtConsumed = 0 : r = oInvoice.GetValue("FreightAmt", nFreightAmtConsumed)
    r = oScript.DebugPrint(sSCRIPT_ID & "00012 oInvoice.GetValue FreightAmt=" & nFreightAmtConsumed & "=FreightAmtConsumed. r=" & r)
    
    nUDF_FreightAmt_Residual = 0: r = oBusObj.GetValue("UDF_FreightAmt_Residual", nUDF_FreightAmt_Residual)
    r = oScript.DebugPrint(sSCRIPT_ID & "00013 oBusObj.GetValue UDF_FreightAmt_Residual=" & UDF_FreightAmt_Residual & "=Freight Not Yet Invoiced. r=" & r)
    
    nUDF_FreightAmt_Residual = nUDF_FreightAmt_Residual - nFreightAmtConsumed
    r = oBusObj.SetValue("UDF_FreightAmt_Residual", nUDF_FreightAmt_Residual)
    r = oScript.DebugPrint(sSCRIPT_ID & "00014 oBusObj.SetValue UDF_FreightAmt_Residual=" & UDF_FreightAmt_Residual & "=Remaining FreightAmt")
    

  • 0 in reply to connex

    I know what's happening.  There is a problem with the Pre-Write event in the sales order business object. 

    Pre-Totals event only happens if there is a change in a detail record.  When you create a new order, you add lines.  Therefore Pre-Totals executes and your UDF is saved.

    Pre-Write saves the sales order header UDF value but it isn't written to sales order history.   I think this is a defect.

    Is there another column you also change in the backorder?  You will need to add your script to a column post-validate event to get around the pre-write problem.

  • 0 in reply to Natasha Chang

    Thanks again and for hanging in here. I'm not using the sales order header Pre-Write to write the UDF. I am using the sales order header Pre-Totals event, but in case there's an issue there also, I put the SetValue for the UDF in a sales order header field Column Post Validate event, but it still doesn't go through to sales order history header. Just to sales order header. Both UDF's are defined/spelled identically.

    What works in history is setting the UDF initially from the sales order FreightAmt field using a CPV script on the same field in sales order header and I exclude setting it when the sales order FreightAmt is modified in sales journal update - that would set the UDF to zero b/c FreightAmt is normally zeroed then.

    What doesn't work in history is my adjusting the UDF downward during sales journal update using a sales order header CPV event (I'm currently using the LastInvoiceSalesOrder field, but also tried FreightAmt). This is when I can "see" the FreightAmt in the related invoice and deduct it from this sales order "UDF_FreightAmt_Residual". I can see from the trace during sales journal update shown below that I get a return code '1' from the SetValue. I also tried a write afterwards. No luck. Thanks for reading about this GIANT project. Solving this will finish it.

  • 0 in reply to connex

    I was testing in sales order entry.  Sales journal update doesn't sync all sales order header fields to history.  You can try updating the sales order history UDF yourself in the Post-Write event of the sales order object.    Sales order history business object is SO_SalesOrderHistoryInquiry_bus.  You can check oSession.Updating <> 0 if you only want this logic to execute in update.

    Edit: I just tried it myself and it failed because of security.  Back to the drawing board,

  • 0 in reply to Natasha Chang

    Thanks again, but using "SO_SalesOrderHistoryInquiry_bus" a SetValue gets retVal = 0 with the LastErrorMsg of "You do not have security rights to modify the record" even though I have full rights. Interestingly, I can write to SO HistoryHeader UDF's from a BOI script.

    I've gotten the same error message in the past with a UDS on AR Invoice History Header trying to modify UDF's there Although I have successfully written BOI scripts that update AR line UDF's in AR history, updating SO header history UDF's with a UDS doesn't seem possible. Ideas? (corrected to say that I have written "BOI" scripts to update AR line UDF's, not UDS's)

  • 0 in reply to connex

    Custom office script checks the UI task to set security.  The UI task is an inquiry task, therefore security is read-only. When you instantiate the object from BOI script, it doesn't do that.  I am out of ideas of how to get it to work for you.  We will fix the pre-write event and look into making it work in update.  But that will be done in supported versions only.

  • 0 in reply to Natasha Chang

    Thank you for your efforts here and explaining the issues!