System Date

I leave SAGE up to keep a program up and running to import orders (Insynch), I have a script looking at the system date to populate a UDF date field when a sales order is put into process.  I am noticing that I haven't had to restart the SAGE application since Sunday 4/23 so the script is populating the udf with the 4/23 date for orders being processed today.  Whats the best way to edit the script to get the correct date?

rVal = 0
nRec = 0
nPull = 0
nUnits = 0
nTotal = 0
sType = ""
dToday = ""

rVal = oBusObj.GetValue("OrderType$", sType)

if sType = "S" Or sType = "B" then

rVal = oBusObj.GetValue("UDF_TOTAL_QTY_REC", nRec)
rVal = oBusObj.GetValue("UDF_TOTAL_QTY_PULLED", nPull)
rVal = oBusObj.GetValue("UDF_UNIT_COUNT", nUnits)

nTotal = nRec+nPull

	if nTotal = nUnits then

	rVal = oBusObj.SetValue("UDF_ALLOCATED$", "Y")
	rVal = oSession.FormatDate(oSession.SystemDate, dToday, "%M/%D/%Y")
	
	dToday = oSession.GetFormattedDate(CStr(dToday))	

	rVal = oBusObj.SetValue("UDF_DATE_ALLOCATED$", dToday)

	end if

end if

  • 0

    Have you tried this?

    rVal = oBusObj.SetValue("UDF_DATE_ALLOCATED$", oSession.SystemDate)

    You should only need to do conversion to a "date" format if you need to do math (like adding a day / week / month...) before the SetValue.  Otherwise the value returned as a Sage date should already be formatted correctly.

    If that doesn't work, use the VBScript "now" function, and convert that to the Sage date format before the SetValue.

  • 0 in reply to Kevin M

    If the system date at the bottom is say yesterday wouldn't it still pull 4/25/2023 by referencing the system date?  Or does it look at the actual pc's system date?

  • 0 in reply to jland47

    I believe system date is the computer date.  Module date is what you see at the bottom of the screen, which might get stale.

    oSession.ModuleDate

    Current module date as YYYYMMDD

    oSession.SystemDate

    Current system date as YYYYMMDD