Basic Testing
Perform a basic test of your code within the Script Editor.
Test the Script
Open the script in the Script Editor.
Best PracticeInspectionReported is an example of a Validation script that checks whether all Activities in an Inspection have a valid status.
At the bottom of the editor, click Test.
In the Test script popup, enter the parameters that need to be passed to test the script and then click Test. In this example, we need to pass the ID of a sample Inspection (dmsID)
Note If you leave userID blank, the system automatically passes your User Name. If you leave workspaceID blank, the system automatically passes the dmsID's workspace ID.
If the test is successful
If the test is successful, a Success message appears at the top of the editor and Script Results appear at the bottom.
Note that, although the script ran successfully, you can tell from the Script Result that the validation check on the sample Inspection did not pass. We now know that the script is doing its job of catching invalid Inspections. The next step would then be to test an Inspection that is valid.
If the test fails
If the test fails, an Error message appears at the top of the editor with an explanation of what caused the error (if known).
Debug With print() and println()
You can use the print()
and println()
functions to return more useful information than just a Success message and the return value. For example, this script returns the pushed message as the return value, but also returns the values for QUANTITY and SUPPLIER_RISK as a debug value.
var messages = [];
if ((item.COST * item.QUANTITY) > 50){
messages.push('Item costs too much for fast-track approval.');
}
else if (item.SUPPLIER_RISK == 'High'){
messages.push('Cannot fast-track approval of parts from high-risk vendors.');
}
println('QTY is '+item.QUANTITY+' and RISK is '+item.SUPPLIER_RISK);
returnValue(messages);