Server based Scripting for the Handheld WMS
The following is a tutorial on Handheld WMS server side scripting capabilities where certain areas have been opened to modification using scripts. Currently, Visual Basic (VB) is the only scripting language supported.
Writing scripts
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. The script consists of one or more functions (described below).
For more information on VBScript visit Microsoft's VBScript explanation.
Notes:
- Do not place any VBScript commands outside of a function in the script. These commands will execute upon the initialization of the script and may cause problems. Also, do not write anything to the screen or attempt to ask any questions of the user as these will not work and may cause the system to halt.
- There can be multiple functions in the same script file.
- Any changes to a script requires the Cadacus WCF service to be restarted.
- Please do not use MsgBox or anything else requiring a user interaction in a live, production script as the script will cause the operation to crash.
Step-by-step instructions
- In the EDI System Setup, select the "Files & Paths" tab and check the "Enable Scripting" box. Enter a directory on the SYSPRO application server where the scripts will be stored.
Notes:
- do not use a path with spaces in the directory name(s). If the path does include a space, use the "short' name for the directory with the space in it, for example, "progra~1", instead of "Program Files"
- Use the "Server" option
- To temporarily disable scripting, uncheck the "Enable Scripting" box
- If SQL is used in the script, enter the username and password here, as well (note, the password is hidden after the window is saved and closed)
- Move script to the folder path defined on the application server in the above example step.
- In the Cross-Reference section of the EDI Menu, select the Handheld WMS Script Definitions menu, and choose "New". In this example, the Module is "Job Receipts" and the Action is "On Verify":
- Modify the query, as needed (example below). Note "HandheldWMS" is the class name.
Public Function GetExpiryDate(ValidationXml) ' As String dim ExpiryDate, sJob, sCmd sJob = HandheldWMS.ElementText("Job") sCmd = "Select something from table where Job='" & sJob & "'" 'return date in YYYY/MM/DD format ExpiryDate = HandheldWMS.SQLExecuteScaler(sCmd) HandheldWMS.StartXML if len(HandheldWMS.SQLError) > 0 then HandheldWMS.StatusXML HandheldWMS.Problem HandheldWMS.MessageXML "Problem with SQL call - " & HandheldWMS.SQLError else if len(ExpiryDate) = 0 then HandheldWMS.StatusXML HandheldWMS.Problem HandheldWMS.MessageXML "Problem with SQL call - No Date returned" else HandheldWMS.StatusXML HandheldWMS.Success HandheldWMS.InformationXML "LotExpiryDate",ExpiryDate end if end if HandheldWMS.EndXML GetExpiryDate = HandheldWMS.ReturnXML End Function
Reference
When utilizing any of the properties or functions in the script is called, "HandheldWMS" is the class.
Calling a function that does not return a value can be done using either of the following methods.
Call XXX(Parameter)
- or -
XXX Parameter
Information sent from the Handheld WMS to the scripts
- Warehouse
- StockCode
- Quantity
- Bin
- Lot
- Serial
- Reference
- Notation
- SalesOrder
- PurchaseOrder
- Job
- Scrap
- Class
- Route
- LedgerCode
Any of the above information may be returned to the handheld and the information provided will overwrite the original. In addition the following information may be returned: LotExpiryDate.
Important: Please note version 2.7.003 (as seen in the add/remove program listing) is required for all the latest functions.
Connections
Script | Description |
---|---|
Company | SYSPRO Company Code |
Server | SQL Server |
SysproOperator | SYSPRO Operator (write only) |
SysproPassword | SYSPRO Operator Password (write only) |
SysproCompanyPassword | SYSPRO Company Password (write only) |
SQLUsername | SQL Username (write only) |
SQLPassword | SQL Password (write only) |
Database | SYSPRO SQL Database |
BuildConnectionString(Username,Password) | Builds a SQL connection string. |
Logging*
Script | Description |
---|---|
Log | Enables the logging (set to True or False) |
LogFile | Sets the name of the log file (default is base\CadacusSFS]CompanyCode-HandheldScripting-YYYYMMDD.txt) |
LogInfo(Message) | Writes the message to the log file if the "Log" variable is true |
WriteLog(Message) | Writes the message to the log file ignoring the current setting of the variable "Log" |
SYSPROError | The last exception thrown by a SYSPRO business object call |
SQLError | The last exception thrown by any SQL call |
* If an exception is caught for SQL or SYSPRO calls and the "Log" variable is true, the exception will be written to the log file.
More
Script | Description |
---|---|
ConnectionString | Sets the connection string; no need to call, the connection string will be created automatically |
VersionString = Version () | Returns a string of the current script library version |
ReleaseDateString = ReleaseDate() | Returns a string of the current script library release date |
Element String = ElementText(Tag) | Returns the information for the specified tag from the XML passed to the script |
Element String = InnerText(XML,Tag) | Returns the information for the specified tag from the XML passed to the function |
Script | Description |
---|---|
StatusString = StatusXML(ReturnStatus) | Creates the <Status> tag for the return XML; it will return the string as well as add to the internal ReturnXML |
Possible return values: | |
Success - successful return status for StatusXML - allows post to continue | |
Problem - Problem return status for StatusXML - displays message - post does not continue | |
Warning - warning return status for StatusXML - displays message allowing Ok/Cancel options | |
Message - successful return status for StatusXML - displays message allowing OK option - Post continues | |
EndPost - successful return status for StatusXML - post is not performed - screen cleared as if a successful post | |
ReturnString = ReturnSuccess(Message) | Creates an entire return XML string with the "Success" status and an optional message |
ReturnString = ReturnProblem(Message) | Creates an entire return XML string with the "Problem" status and a message |
ReturnString = ReturnWarning(Message) | Creates an entire return XML string with the "Warning" status and a message |
ReturnString = ReturnEndPost(Message) | Creates an entire return XML string with the "EndPost" status and a message |
ReturnString = ReturnXML() | Returns the XML created by the StartXML, EndXML, etc. |
Script | Description |
---|---|
MessageXML(Message) | Creates the <Message> tag for the return XML. (*) |
InformationXML(Tag,Information) | Creates the tag for the return of information in the return XML. (*) |
StartXML() | Creates the root level of the return XML. (*) |
EndXML() | Closes the root level of the return XML. (*) |
Object = SQLExecuteScalar(Command) | Executes the SQL command and returns the first value |
Object = SQLExecuteNonQuery(Command) | Executes the SQL command and returns the number of records processed |
Object = SQLExecuteReader(Command) | Executes the SQL command and returns a SQLDataReader object |
SQLEsc(Object) | Returns a string formatted for SQL of the object |
XMLOut = Query(BusinessObject,XMLIn) | Calls the SYSPRO WCF service to process the query; automatically logs in/out of e.Net |
XMLOut = Post(BusinessObject,XMLParameters, XMLIn) | Calls the SYSPRO WCF service to process the post; automatically logs in/out of e.Net |
SaveXML(Filename) | Saves the XML sent to the script to the specified file |
PadLeft(String,Length,PadCharacter) | Pads the string on the left with the PadCharacter to make a string of "Length" characters long |
PadForSYSPROKey(String) | Pads the string with "0"'s on the left to 15 digits to change a numeric value into the SYSPRO Key |
(*) The information will be added to the internal ReturnXML property in addition to being returned to the script.
Testing outside of SYSPRO
Testing outside of SYSPRO is an advantage during the initial testing stages. To do so, please add the following section to the "front" of the script shown above.
When testing, a 32-Bit command prompt must be used. Any other method will result in a Cadacus.HandheldRuntime not found error.
' --- For testing only, Remove or Comment out before using set HandheldWMS=CreateObject("Cadacus.HandheldRuntime") dim SampleXML SampleXML = "<CustomValidation><Job>123</Job><Quantity>333</Quantity></CustomValidation>" HandheldWMS.Company = "O" HandheldWMS.Server = "SQLserver" HandheldWMS.Database = "SysproCompanyX" HandhedWMS.BuildConnectionString "Username","Password" 'on error resume next MsgBox GetExpiryDate(SampleXML) ' --- Everything above this line for testing only, Remove or comment out before using ' The rest of the script would be put here.....
Now using cscript, launch the script. For example:
cscript GetExpiryDate.vbs /x /d
This command launches the script (/x) using the debugger (/d). For more details on cscript go here.
Debugging does require Microsoft Visual Studios to be installed.