Sage MAS 90 and 200 Sage MAS 500 blogs Product Feedback Support Training
Reply
Contributor
dosborn
Posts: 25
Registered: 12-15-2011
0
Accepted Solution

Get Updated Sales Order Person No, Expiration Date & Total on Accept

I need to fire off a script when a sales order is saved, grab some data and update a remote database. I have created a secondary accept button, tied a script to my button, and hidden the original accept button. 

My script successfully runs and I can get the order number and order date, but I need to grab salespersonNo, expiration date and total and can't seem to figure how to do that.

 

salesOrderNo = "" 
salesPersonNO = "" 

retVal = oScript.InvokeButton("BT_ACCEPT") 


rtnVal = oBusObj.GetValue("SalesOrderNo$", salesOrderNo) 
customerNo = [SO_SalesOrder_bus_CustomerNo] 
orderDate = [SO_SalesOrder_bus_OrderDate] 



'Parse Order Date 
Dim theYear, theMonth, theDay, result 

parsedOrderDate = "" 

If Len(orderDate) = 8 And IsNumeric(orderDate) Then 
     theYear = Mid(orderDate,1, 4) 
     theMonth = Mid(orderDate,5, 2) 
     theDay = Mid(orderDate, 7, 2) 
     result = theMonth & "/" & theDay & "/" & theYear 

     If IsDate(result) Then 
       parsedOrderDate = CDate(result) 
     End If 

End If 

 

Sage Employee
jepritch
Posts: 237
Registered: 08-25-2009
0

Re: Get Updated Sales Order Person No, Expiration Date & Total on Accept

Hi dosborn,

 

You should be able to get the salesperson number and expiry date in the same fashion as the sales order number.  Also, I would recommend retreiving these values BEFORE you invoke the real Accept button, as some of these values may be cleared after.  Also, you could actually do this entire script on a Post or Pre Write event as a user-defined script.  Your choice.

 

slsperson = ""

expireDate = ""

retVal = oBusObj.GetValue("SalespersonNo$", slsperson) ' keep in mind there are several salesperson fields if using split commissions and each has their own division number if you are using divisions.

retVal = oBusobj.GetValue("ShipExpireDate$", expireDate) ' this will be in YYYYMMDD

 

The order total however, is a calculation of several fields:

 

taxAmt = 0

nontaxAmt = 0

salestax = 0

freight = 0

discount = 0

 

retVal = oBusObj.GetValue("TaxableAmt", taxAmt)

retVal = oBusObj.GetValue("NonTaxableAmt", nontaxAmt)

retVal = oBusObj.GetValue("SalesTaxAmt", salestax)

retVal = oBusObj.GetValue("FreightAmt", freight)

retVal = oBusObj.GetValue("DiscountAmt", discount)

 

orderTotal = 0

orderTotal = taxAmt+nonTaxAmt+salestax+freight-discount

 

Hope this helps.

Elliott

 

Regular Contributor
Gator
Posts: 272
Registered: 12-05-2008
0

Re: Get Updated Sales Order Person No, Expiration Date & Total on Accept

Also, if this is being run from a button script, then all the values  you need can just be passed into the script.  No need to do any business object queries.

Moderator
Natasha
Posts: 180
Registered: 07-15-2009
0

Re: Get Updated Sales Order Person No, Expiration Date & Total on Accept

Why do you need to add a new button?  You can just write a script that runs in the SO_SalesOrderHeader - Post_Write event. 

 

You can just use GetValue to get the fields you need.

 

retVal = oBusObj.GetValue("SalespersonNo$", salespersonno)

retVal = oBusObj.GetValue("ShipExpireDate$", expiredate)

 

Order total is not stored.  It can be calculated as TaxableAmt + NonTaxableAmt + SalesTaxAmt + FreightAmt - DiscountAmt.

 

 

 

 

 

Natasha Chang
Sr. Software Engineer
Sage 100 ERP
Super Contributor
connex
Posts: 795
Registered: 10-29-2008
0

Re: Get Updated Sales Order Person No, Expiration Date & Total on Accept

You could do it with either of the techniques you are already using:

 

rtnVal = oBusObj.GetValue("SalesPersonNo$", SalesPersonNo)
rtnVal = oBusObj.GetValue("ShipExpireDate$", ShipExpireDate)  

 or if you add the following fields with the MS Script Variable Selection button...

 

SalesPersonNo = [SO_SalesOrder_bus_SalespersonNo]
ShipExpireDate = [SO_SalesOrder_bus_ShipExpireDate]

 

Dan Burleson
Sage Authorized Consultant - Ask me about advanced scripting!
e-mail me here
Contributor
dosborn
Posts: 25
Registered: 12-15-2011
0

Re: Get Updated Sales Order Person No, Expiration Date & Total on Accept

Thanks, I am a bit baffled because I tried grabbing SalesPersonNo that way and it didn't work, but now it seems to be.  I tried putting it in the post write initially, but was having some issues.  Once I get it working I will try moving it back to the post write and see if I have success.

Super Contributor
connex
Posts: 795
Registered: 10-29-2008
0

Re: Get Updated Sales Order Person No, Expiration Date & Total on Accept

...talk about an avalanche of support. Impressive!:smileyhappy:

Dan Burleson
Sage Authorized Consultant - Ask me about advanced scripting!
e-mail me here
Contributor
dosborn
Posts: 25
Registered: 12-15-2011
0

Re: Get Updated Sales Order Person No, Expiration Date & Total on Accept

Thanks for on the feedback.  I moved the script to post write on SO Sales Order Detail, but it doesn't seem to fire any suggestions?

Regular Contributor
Gator
Posts: 272
Registered: 12-05-2008
0

Re: Get Updated Sales Order Person No, Expiration Date & Total on Accept

I usually put a oScript.DebugPrint at the beginning of my scripts to make sure they are getting hit when I want them to (using the Program Trace with the Debug option in the INI file on).

 

Also make sure you have "Allow External Access" checked in the company you are working on in Company Maintenance.

Sage Employee
jepritch
Posts: 237
Registered: 08-25-2009
0

Re: Get Updated Sales Order Person No, Expiration Date & Total on Accept

Hi dosborn,

 

In addition to Gator's suggestion, make sure it does get compiled into the script for the object as well.  (It probably has).  Also, I just noticed in your earlier post, that you added this to the SO_SalesOrderDetail : Post-Write event?  I think you should put it on the SO_SalesOrderHeader : Post-Write event. 

 

I agree wholeheartedly with Gator, as that DebugPrint can certainly be your friend when debugging :smileyhappy:

 

Elliott