Testing a script
The scripting application now has a Test button to help test the script that you authored.
You can use Test to prepare the test data and execute the script right from the test dialog.
All the logs would be printed out in the Process Log text area without enabling any logging as long as the
service variable was used for the log.
In cases where the script needs an MBO for the test, the dialog provides a way (
Object Path) to select the MBO for testing the script. The following sample
way shows how to set the object path.
Note that if you had set the path value to just
ASSET, it would have created a new MBO for the Asset and used that for this script.
This selects an asset with assetnum SPFN0001 and uses the MBO for the
mbo variable in the script context.
This can be leveraged for testing Object or Attribute or Action or Condition Launch point scripts.
The dialog allows you to set attribute or value pairs to prepare the MBO for the test using the `Set Attribute Value’ table.
The process makes a best attempt to not commit the modified MBO, but in certain cases this is unavoidable. For example, in cases where the event is after a commit, the MBO is already committed.
For other cases, the script code itself might initiate a commit. The following screen shot showcases some of the test functionalities.
For tesing object init event:
Note that the resulting MBO is serialized and presented in the Data field of the dialog. This helps you to validate when the the script execution resulted in the right state of the MBO.
For testing “On Add” object events:
As apparent you set values: ASSETNUM TESTADD10 ASSETTYPE FLEET
This results in an error because ASSETNUM and ASSETTYPE mismatch - as shown in the screen shot.
The following screenshot is when there is no error thrown:
The following example is from app validate event:
Object path: ASSET Set values: ASSETNUM TESTVAL1 ASSETTYPE FLEET Result: Error is thrown because ASSETNUM and ASSETTYPE mismatch
Can Add Event
The following screen shot shows the
Can Add Event in which you select a PO which does not have a vendor and attempt to add a POLINE, using the object path notation to invoke the script.
Object path: PO[ponum=‘1056’]/POLINE Result: Error is thrown because PO do not have vendor
The following screenshot shows the
Can Delete Event test:
Object path format: ASSET[assetnum=‘7500’] Result: Error is thrown of ASSETTYPE is FLEET
Adding setup logic for virtual (aka Nonpersistent) MBOs on setup:
Object path format: ASSET[assetnum=‘ASSET1’ and siteid = ‘BEDFORD’]/ASCHANGESTATUS Result: Status set BROKEN and MEMO set to Test Broken Note: property mxe.script.callsetuponinit need to be set to 1
Testing OBJECTNAME.NEW script:
Object path format: ASSET Result: EQ1 set to TEST EQ1
Testing OBJECTNAME.DUPLICATE script:
Object path format: ASSET[assetnum=‘1001’ and siteid=‘BEDFORD’] Result: ASSETNUM set to null
Testing Attribute validate event:
Object path format: ASSET Attribute values: ASSETNUM ATTRTEST1 PURCHASEPRICE 300 Result: Some error is thrown because PURCHASEPRICE > 200
Testing Attribute action event:
Object path format: ASSET Attribute values: ASSETNUM ATTRAC1 PURCHASEPRICE 100 Result: EQ7 set to 50
Testing Attribute init event:
Object path format: ASSET[assetnum=‘1001’] Result: EQ2 set to ASSETNUM (1001)
Testing lookup scripts:
Object: ASSET Attribute: EQ11 Object path format: ASSET[assetnum=’ASSET1’] Result: Values for lookup will be from ALNDOMAIN PHONETYPE
Object Structure Script Processing - Inbound:
Use the “select file” option to select a xml or json file:
Test XML: MXITEM1.XML Test JSON: MXITEM1.JSON Result: Transaction is skipped for LOTTYPE=NOLOT
Object Structure Script Processing - Inbound:
Test XML: MXINVISSUE1.XML Test JSON: MXINVISSUE1.JSON Result: Transaction is skipped for ISSUETYPE=RETURN
Testing object structure inbound:-Functions: beforeMboData(ctx) and afterMboData(ctx)
Test XML: MXITEM2.XML Test JSON: MXITEM2.JSON Result: Set COMMODITYGROUP based on HIERARCHYPATH
Testing Object structure inbound function: changeStatus(ctx)
Test XML: MXITEM3.XML Test JSON: MXITEM3.JSON Result: Change Status with MEMO
Object Structure Script Processing - Outbound
Object path format: PO[ponum=‘1002’] Result: Set description Skip POLINE without ITEMNUM Skip TAX fields if TEXED is false
Object Structure Query:
Name: OSQUERY.MXAPIWO.EMXWOFILTER Object path format: WORKORDER Parameters: ASSETNUM 11200 STATUS WAPPR Result: Where clause applied to MboSet (assetnum=‘11200’ and status = ‘WAPPR’)
Object Structure Actions:
Name: OSACTION.MXAPIASSET.SETPRIORITY Object path format: ASSET Parameters: ASSETNUM 11200 STATUS IT Result: Sets priority based on the ASSETTYPE
Event Filters For Publish Channel:
Name: PUBLISH.MXASSETINTERFACE.EVENTFILTER Object path format: ASSET Parameters: ASSETNUM 11200 STATUS IT Result: Sets priority based on the ASSETTYPE
Exits for Publish Channels External Exit:
Name: PUBLISH.MXASSETINTERFACE.EXTEXIT.OUT Object path format: ASSET[assetnum=‘1008’]
Result: Set description to status if status is OPERATION
Exits for Publish Channels User Exit Before:
Test XML: MXASSET1.XML Test JSON: MXASSET1.JSON Result: Skip transaction if STATUS=BROKEN
Exits for Publish Channels User Exit After:
Test XML: MXASSET1.XML Test JSON: MXASSET1.JSON Result: Display STATUS from IR record and EQ3 (set in before exit) from ER record
Enterprise service External Exit script:
External System: EXTSYS1 Test XML: MXITEM1.XML Test JSON: MXITEM1.JSON Result: Skip transaction if LOTYPE = NOLOT Skip transaction if ITEMNUM is null Set description to ITEMNUM
Invoke Channel Scripting
Name: INVOKE.ZIPCHANNEL.USEREXIT.OUT.AFTER Language: js New/Existing: New Object path format: PERSON Complete process: TRUE Attribute values: PERSONID TEST5 CITY BOSTON Result: Set STATEPROVINCE and POSTALCODE
Name: TESTENDPOINT Language: Python Test Script Type: ENDPOINT Test XML: MXITEM1.XML Test JSON: MXITEM1.JSON Result: Display payload Display script name from metadata
Condition Launch Point
Name: SUMCOST Language: Python Where clause: assetnum = ‘11200’ Result: Return True of sum of SPAREPART QTY > 10 Return False of sum of SPAREPART QTY < 10
Action Launch Point
Name: CACLMETER Language: Python Object path: ASSET[assetnum = ‘11430’] Result: Set EQ7 to ASSETMETER.OLDREADING
Name: INVOKEREST Language: Python Query parameters: personid = ‘LIBERI siteid = ‘FLEET’ Result: Throw exception if site is invalid SET LOCATIONSITE to siteid
Name: MAXROLE.EMXROLE Language: Python Where clause: assetnum = ‘11430’ Result: Check for PERSONGROUP TIER1 and TIER2
Result: Display original and additional message
Name: STANDARDDEV Language: Python New/Existing: Existing Object path format: ASSET[assetnum=’11430’] Properties: param = “ALLWO” param = “estlabcost” Result: Display standard deviation