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
  • 0
    SUGGESTED

    Here is the script I use on purchase order header to write the date. It should give you clues.

    retVal=oBusObj.GetValue("RequiredExpireDate$",sDate)
    retVal = oSession.FormatDate(sDate, newDate, "%M/%D/%Y")
    newDate = DateAdd("D", 25, newDate)
    newDate = oSession.GetFormattedDate(CStr(newDate))
    retVal = oBusObj.SetValue("UDF_HOUSTON_DATE$", newDate)

  • 0 in reply to BigLouie

    Hi

    I tried usig the above script, however since the Invoice Date is defaulted on the form load, it didnot pick up the value and returned for the new udf date field. Is there a way we can get the system date ?

    Please advise and confirm. Thanks

    AJ

  • +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.

Reply
  • +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.

Children
No Data