Copying the Date value into new date UDF on the Invoice Data Entry

SOLVED

Hi 

We have a requirement, where when a new invoice is getting entered in AP, using a VBScript copy the Invoice Date to a new UDF.

I did try to put the same using the Post Validate event on the Invoice Date, but it's not copying the data into the new UDF field. 

Anybody came across similar requirements, please share their findings/logic or any other solution approach. 

Script 1 - with Message box confirmation works fine 

If oSession.CompanyCode="TST" Then

                 'Declare Variables

                dInvoiceDate = ""

                dVendorInvDate = ""

                sMsg = ""

                 If oBusObj.EditState = 2 Then

                                'get values

                                retval = oBusObj.GetValue("InvoiceDate$", dInvoiceDate)

                                retval = oScript.DebugPrint("The value of the Invoice Date is: " + dInvoiceDate)            

                                If dVendorInvDate = "" Then

                               sMsg = "The Invoice Date is " + dInvoiceDate +". Would you like to retain the same as the Vendor Invoice date"

                                Set oUI = oSession.AsObject(oSession.UI)

                                retMsg = oUI.MessageBox(".Y2", sMsg)

 

                                                If retMsg = "YES" Then

                                                'retval = oScript.DebugPrint("The user clicked yes")

                                                retval =oBusObj.SetValue("UDF_Vendor_Invoice_DATE$",dInvoiceDate)

                                                retval = oBusObj.SetValue("UDF_Vendor_Invoice_DATE$",dInvoiceDate)

                                                Else

                                                'retval = oScript.DebugPrint("The user clicked No")

                                                retval =oBusObj.SetValue("UDF_Vendor_Invoice_DATE$",dVendorInvDate)

                                                End If

                                End If

                End If

End If

Script 2 - without Message box confirmation does not work.

If oSession.CompanyCode="TST" Then
 'Declare Variables
 dInvoiceDate = ""
 dVendorInvDate = ""
  
 If oBusObj.EditState = 2 Then
  'get values
  retval = oBusObj.GetValue("InvoiceDate$", dInvoiceDate)
  retval = oScript.DebugPrint("The value of the Invoice Date is: " + dInvoiceDate)
 
  If dInvoiceDate <> "" Then
  retval = oBusObj.SetValue("UDF_Vendor_Invoice_DATE$", dInvoiceDate)
  Else
  retval = oBusObj.SetValue("UDF_Vendor_Invoice_DATE$",dVendorInvDate)
  End If
End If
End If

Also, is there a way to capture the sysdate for the new UDF date field. Please advise and recommend.

Thanks

AJ

Parents Reply Children
  • +1 in reply to AJ@Marki
    verified answer

    You can use either the SystemDate or ModuleDate properties of the oSession object. They will be in the required YYYYMMDD format.

    Regarding the event firing, if you attach your script to the post read event and check the EditState property being 2, you can set the value on new records. If you don't need the value to be visible to the user while entering a new record, you could always attach the script to the pre write event.

  • 0 in reply to AJ@Marki

    For something like an invoice date for a new invoice, you might try one of these events instead of looking at the column... or try PreTotals (but I am not sure how that works for AP invoices).

  • +1 in reply to Kevin M
    verified answer

    I don't think script initialization will work for this purpose since I believe it only executes once when the task is first launched. Which is when the code is first read and added to the MSScriptControl object.

    Set default values should work but it only executes when a new record is created and sage 100 processes the default values logic whereas post read or pre write gives you a little more flexibility.

  • 0 in reply to David Speck

    yes, the Post-Read event on the header table captured it and worked exactly how we wanted. 

    Thanks/AJ

  • 0 in reply to Kevin M

    Thanks , I had the same doubt, but the Post-Read recommended by David, just did work exactly how we expected. Appreciate your response and guidance.

  • 0 in reply to David Speck

    For completeness sake, if you are always going to use either the module date or system date for a Date UDF for new records, you can just set the default value to either when maintaining the UDF.

    A script is useful when you want to calculate a new date value based on something else or need to have the date value changed due to another event occurring. Which i thought is what you were wanting to do since you were wanting this to trigger if someone changes the invoice date field.