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