Date Script Check

I used a few other post to compile this script to add 7 days to the order date and populate a UDF date field.  I tested the script and it worked but I get nervous about how I am getting the results, is it best method wise?  Could someone please check it and tell me if there is a better way .

rVal = 0
nCustomerNo= ""
rushDate = ""
newDate = ""

rVal = oBusObj.GetValue("OrderDate$", rushDate)
rVal = oBusObj.GetValue("CustomerNo$", nCustomerNo)

If nCustomerNo = "2407000" then

	rVal = oSession.FormatDate(rushDate, newDate, "%M/%D/%Y")
	newDate = DateAdd("D", 7, newDate)
	newDate = oSession.GetFormattedDate(CStr(newDate))

	rVal = oBusObj.SetValue("UDF_NEEDDATE$", newDate)
			
End If

Parents
  • 0

    Looks pretty good. I guess customer 2407000 is important.  Also do you use Divisions?  If you do you would need to include the division.

  • 0 in reply to BigLouie

    Ha, well they will not be once everyone knows we can script a rush date on every order for their customers.  No divisions.  In an excel formula I was able to leave off weekends and only count business days, is this possible in Sage?  Didn't see any post pertaining to that option.

  • 0 in reply to jland47

    We had someone who wanted to force users to specifically choose a ship date, instead of accepting a default... so we set the default value of that date field to something impossible (ex. 1999-12-31) and did a pre-write script to block saving an order with that value in that field (...SetError...).

    What you're doing should be fine, but an alternate approach might be better as a business process.

    To count ## week days, you can use the VBScript "weekday" function for that calculation (...adding a different number, depending on your beginning week day value)... but holidays won't be considered.

  • 0 in reply to Kevin M

    Running into same problems with script firing off because of the logic of the import of order data.  I was able to set it to a table-prewrite because we run multiple imports against SO throughout the day so the order eventually gets updated and the UDF set.   So I thought if I could simplify the script to just look at the customerno and then set the UDF with a vbs formula to account for just workdays might be better.  However this script gives an error when entering a SO for this customerno. 

    rVal = 0
    nCustomerNo = ""
    
    rVal = oBusObj.GetValue("CustomerNo$", nCustomerNo)
    
    If nCustomerNo = "2407000" then
    
    	newDate = DateAdd("w",7,Now())
    	rVal = oBusObj.SetValue("UDF_NEEDDATE$", newDate)
    
    End if

Reply
  • 0 in reply to Kevin M

    Running into same problems with script firing off because of the logic of the import of order data.  I was able to set it to a table-prewrite because we run multiple imports against SO throughout the day so the order eventually gets updated and the UDF set.   So I thought if I could simplify the script to just look at the customerno and then set the UDF with a vbs formula to account for just workdays might be better.  However this script gives an error when entering a SO for this customerno. 

    rVal = 0
    nCustomerNo = ""
    
    rVal = oBusObj.GetValue("CustomerNo$", nCustomerNo)
    
    If nCustomerNo = "2407000" then
    
    	newDate = DateAdd("w",7,Now())
    	rVal = oBusObj.SetValue("UDF_NEEDDATE$", newDate)
    
    End if

Children