Scripting for Shipping
The following is an explanation of the scripting capabilities in the Shipping solution
Certain areas of the Shipping solution have been opened to modification via scripts. Visual Basic (VB) is the only scripting language currently allowed.
Warning: Scripts must be carefully tested as the Shipping system does no validation on the returned information.
In the EDI System Setup, select the "Files & Paths" tab. Check the "Enable Scripting" box and enter a directory on the SYSPRO Application server where the scripts will be stored.
Do not use a path with spaces in the directory names. If the path does include a space, use the "short" name for the directory with the space in it (i.e. "progra~1" instead of "Program Files").
To temporarily disable scripting, uncheck the "Enable Scripting" box.
Writing a script
Any text editor can be used to write a script and any file naming convention may be used with the exception of spaces-- do not use spaces in the script file name. Generally VB Scripts should use the ".vbs" extension, but this is not required. Notes:
Shipping Script Overview
There are four basic steps to scripting in Shipping:
Use Case Scenario
Client requests a shipping scenario where flat rates should be charged when freight bills are over a given threshold.
For example, an order with an actual freight charge cost of $360 is ready to ship; however, since the client desires flat rates be charged over a threshold of $300, a flat rate of $500 should be the new computed freight charge for the shipment.
The following steps demonstrate how the above example can be accomplished using scripting capabilities in the Shipping solution.
1. Enable scripting and set the path to the script file
To enable scripting, go to the EDI System Setup menu, "Files and Paths" tab. Select the checkbox to enable scripting. On the SYSPRO application server, determine where the locally developed scripts will be stored and create a new directory there. In the following example, a directory called "SCRIPTS" has been created within the S:\DATA\ directory, so the full example path of S:\DATA\SCRIPTS\ must be entered (or selected by clicking and browsing via the magnifying glass browse button) in these settings.
2. Create and place the script file
In this example, an empty script file, named FreightCalc.vbs, can be created and placed in the path indicated in step 1 above, Examples of writing the script follow further below.
3. Identify the XML business object elements expected from Shipping
Scripting in Shipping receives XML data from SYSPRO business objects, operates on the XML, then returns XML back to the business object for SYSPRO to add or change the desired data. For more information on SYSPRO business objects, go the the SYSPRO Support Zone for Developers, or contact SYSPRO for assistance.
In this use case scenario, the XML from Shipping might look like the following example:
<CustomCharge> <Script>FreightCalculator.vbs</Script> <Function>Custom</Function> <SalesOrder>001595</SalesOrder> <Customer>0000001</Customer> <ActualCost>27.24</ActualCost> </CustomCharge>
4. Begin building the script function to compute a new freight charge
The script function is where the custom work is done to meet the client requirements. The name of the function will be later referenced in SYSPRO settings. In this example, the function is called CustomCharge and the first statement gets the XML input from SYSPRO and parses the input into previously defined variables.
Note: the complete script for this example is available near the bottom of this section.
Dim SalesOrder Dim Customer Dim ActualCost ... Function CustomCharge(XmlIn) ' As String ... Call ParseXML(XmlIn) ... End Function Private Sub ParseXML(XmlIn) Set xmlDoc = CreateObject("Msxml2.DOMDocument") xmlDoc.async = false xmlDoc.loadXML(XmlIn) For Each Node In xmlDoc.ChildNodes For Each SubNode In Node.ChildNodes Select Case SubNode.NodeName case "SalesOrder" SalesOrder = SubNode.Text case "Customer" Customer = SubNode.Text case "ActualCost" ActualCost = CCur(SubNode.Text) case "ComputedCost" ComputedCost = CCur (SubNode.Text) case "ComputeCharge" ComputedCharge = CCur(SubNode.Text) End Select Next Next End Sub
5. Add the calculation to the CustomCharge function
Function CustomCharge(XmlIn) ' As String Call ParseXML(XmlIn) ... IF ActualCost > 300.00 Then Charge = 500.00 Else Charge = ActualCost End If ... End Function
6. Complete the CustomCharge function and return the computed charge and cost in the proper XML format
Function CustomCharge(XmlIn) ' As String Call ParseXML(XmlIn) IF ActualCost > 300.00 Then Charge = 500.00 Else Charge = ActualCost End If Cost = ActualCost CustomCharge = FormReturnXML() End Function Private Function FormReturnXML() FormReturnXML = "<CustomCharge>" FormReturnXML = FormReturnXML & "<Charge>" & FormatNumber(Charge,2) & "</Charge>" FormReturnXML = FormReturnXML & "<Cost>" & FormatNumber(Cost,2) & "</Cost>" FormReturnXML = FormReturnXML & "</CustomCharge>" End Function
Get the complete sample VBScript file here.
7. Set the "Carrier Freight Charge Code" scripting options
In the EDI Cross-Reference Maintenance menu, open the "Carrier Charge Information" dialog settings for the desired charge code and select the "Scripting" tab. Enter the VBScript name in the "File:" input box and enter the custom function name in the "Function:" input box-- in this example the function is "CustomCharge".
8. Test a shipment
In this example of scripting in the Shipping solution, the actual freight cost for this shipment is $360.00.
After completing this sample shipment, the Shipment Viewer shows the flat rate of $500 set based on actual frieght of $360.00 exceeding the threshold defined by the client.