Introduction to Infoplus Scripts

Customize Infoplus by using scripts. You can write and run your own scripts to customize user reports, build business rules, and more.

One way of customizing Infoplus to fit your unique needs is to use Infoplus Scripts. You can write and run your own Scripts, which are user-defined blocks of JavaScript code, without leaving Infoplus. Scripts give you the power to use source code to customize user reports and build your business rules, however complex or unique they may be, directly inside the Infoplus platform.


Due to the ever-changing nature of writing and maintaining scripts, Infoplus does not provide support in this area. We recommend someone in your IT Department handles scripting requests internally so that you keep all control over the process.


Infoplus has a number of pre-defined areas where scripts can be used (for example, when generating a user report, or when sending an order to an external shipping system (e.g., ShipStation)).  These different “types” of the script are indicated by the Script Type field on the Script record in Infoplus.  See below for a listing of the available Script Types in Infoplus, with links to further details and examples of all types.  


There is also a somewhat generic script type called Record, which is the type of script which a user can run at any time against any one or more records from almost any tables in Infoplus.  This script type can also be used as the action that runs when Triggers are fired against a new or updated record, can be scheduled to run automatically against records matching a Smart Filter, or can be manually executed on-demand. 


Scripts have many uses. For example, you could write a script to:

  • Make sure every new Warehouse Location you build is set to Online.
  • Split Orders between Warehouses if they contain specific SKUs.
  • Increase all of your Item footprints by a quarter of an inch.
  • Change the Billing Type on Warehouse Locations based on their Level.
  • Split each Order's serial number into its own row on a report.

Create a Script

  1. In Infoplus, go to the Script table. Two ways:
    - From the DashboardClick the “Account Management” tab, click the “Scripts” App, then click the “Script” Table.
    - From the Quick Actions shortcut: Press a dot (period) on your keyboard, then select “Script” from the list of Quick Actions.

  2. Click the Create New button. The Creating New Script window appears.

  3. Enter a Name for the Script.
  4. Select the Script Type.  See below for details about the various script types.  Note that depending on the type you select, additional fields may display.

  5. If it is displayed, select the Record Type on which the Script will operate. You may choose any Record Type available in the Infoplus API.
  6. If it is displayed, select the API Version with which the Script will be compatible. Each Script you create works with a specific version of the Infoplus API . By choosing a fixed version of the Infoplus API, you can be confident that the fields and methods your Script calls will always be available, so a Script you write today will continue to work in the future as new versions of the Infoplus API become available.
    NOTE: It is recommended that the latest release version always be used for new production-ready Scripts. For testing new functionality, the Beta version may used, but it is not recommended to use the Beta version for production, as the interfaces on the Beta API may change regularly.
  7. Enter the Code that describes the operation of the Script. This code is written in JavaScript. Here is a sample Script that will set new Warehouse Locations to be Online:

Script Code & Execution Details

Script Language & Environment

Infoplus Scripts are written using JavaScript.  However, this JavaScript is executed inside a Java virtual machine on the Infoplus backend (specifically, at the time of this writing, the script engine is Rhino 1.7.7.1).  


This means that while you can always use JavaScript syntax (if, for, try, var, function, etc), you may not always be working with JavaScript objects - rather - sometimes the objects you have access to are Java objects (and at the time of this writing, Java 8).  


So, for example, when you have an array or list type variable, if it is a JavaScript array, you could iterate over it using the standard JavaScript syntax of:

for(var i=0; i<myList.length; i++)
{
utils.log(myList[i]);
}

But, if it is a Java list (an instance of java.util.List), then rather than having a .list property, it would have a .size() method, and rather than using [i] syntax to access the contents of the list, you would need to call the .get(i) method.  So your loop would look like:

for(var i=0; i<myList.size(); i++)
{
utils.log(myList.get(i));
}

Infoplus API Integration

Most types of Infoplus Scripts work closely with the Infoplus API, in two specific ways:

  1. Scripts may have access to objects which correspond to records from Infoplus, and which match the shape of Infoplus API model objects, as described on the API resource documentation.   

  2. All scripts have access to an object called infoplusApi, which has methods for working with the Infoplus API, such as .search(), .getById(), .add(), .update(), .delete(), .addTag(), .addAudit(), and more.  See details about the infoplusApi object 

When creating an Infoplus Script, you may be prompted for what API Version you want to work with, which will control what fields are available in your record model objects, and what methods you can call on the infoplusApi object available to your script.  

Exiting a Script

It is possible to exit a script in the middle by using a return; statement (regular exit) or a throw statement (exit with error):

  • When a Scripts runs, it is wrapped inside of an immediately invoked function expression (IIFE). This implies that if a Script needs to exit prematurely (for example, if it evaluates a field on the record that it receives as input and determines that no further action is needed), it can do so by executing a return; statement. Infoplus will discard any value returned from a Script.  The Script Log for a Script which exits in this way will show "Had Error = false". 
  • If you want a Script to exit with an Error state, this can be done by using a throw statement. The value thrown will be recorded in the Script Log's Error field. A script that exits via a throw will show "Had Error = true" in the Script Log table.  If a script is running as a Trigger, and it exits with an Error, the Trigger will issue an Alert.   

Context / Global Objects

The following variables are available in runtime context of an Infoplus Script as global variables:  

  • record (The actual variable name depends on the Script's Record Type)
    • The record which the script receives as input will be available in the Script's context, and it will be named after the record type that the Script works with, where the naming convention will match that used for model types in the Infoplus API.  For example, for a Script that runs against Orders, this variable will be named order.  For Item Receipts, it will be named itemReceipt. The general rule for that naming convention is initial-lower-case, camel-back, singular.  This object will also be available under the generic name record.  
    • This object is the API Model representation of the record that the Script is being executed against (whether that's the record that a Trigger's Smart Filter matched or the record that you selected when manually running a Script). The properties of this object can be found in the Infoplus API reference.
  • infoplusApi
    • This object provides full access to the Infoplus API, to allow a Script to get individual records (by id), search for records, and add, update, or delete records. The methods in this object take, as their first parameter, the name of the record type that you want to work with. For example, "order", "orderLine", "itemReceipt", etc. 
    • The full list of methods available on this object are:
      • List<recordModel> search (recordType, filter, page, limit, sort)
        • Looks up a list of records from Infoplus that match the specified filter.  
          • recordType must be a string matching one of the resource types listed on the Infoplus API reference, such as "order" or "item"
          • filter must be a string such as "sku eq 'ABCD'"
          • page may be null (in which case it defaults to 1), or an integer starting at 1
          • limit may be null (in which case it defaults to 20), or an integer between 1 and 250.
          • sort may be null or a field name from the resource, optionally prefixed by a '!' character to reverse the sort. 
          • See the Infoplus API reference for further details on the filter, page, limit, and sort parameters.  
          • Example:  var itemList = infoplusApi.search("item", "sku like 'A%' and status eq 'Active'", null, 100, 'sku');
      • recordModel getById (recordType, id)
        • Looks up a single record from Infoplus, by its primary key / id. 
        • Example:  var order = infoplusApi.getById("order", 1701);
      • recordModel constructModel (recordType)
        • This method is used to construct a new apiModel object of the specified type, which can be passed in to the add method to insert a new record into Infoplus. 
        • Example:  var newOrder = infoplusApi.constructModel("order");
      • recordModel duplicate (recordType, recordModel)
        • This method takes a recordModel and returns a copy of it, with the values of certain fields set to null (such as non-editable or system-generated ones). The object that is returned can be readily passed into the add method (after adjusting any values that are needed) to insert a new record as a copy of the input recordModel.  
        • Example: var duplicateQuickReceipt = infoplusApi.duplicate("quickReceipt", originalQuickReceipt);
      • recordModel add (recordType, recordModel)
        • Saves a new recordModel into Infoplus.
        • Example: var addedThirdPartyParcelAccount = infoplusApi.add("thirdPartyParcelAccount", newThirdPartyParcelAccount);
      • recordModel update (recordType, recordModel)
        • Saves updates to an existing recordModel into Infoplus. The existing record is identified by the primary key field within the recordModel. For example, orderNo for Orders, id for most other recordTypes.  
        • Example: var updatedOrderSource = infoplusApi.update("orderSource", orderSource);
      • recordModel updateCustomFields (recordType, recordModel)
        • Saves updates to the customFields in a recordModel into Infoplus. 
        • Example: var updatedVendor = infoplusApi.updateCustomFields("vendor", vendor);
      • void delete (recordType, id)
        • Deletes the specified record from Infoplus.  
        • Example: infoplusApi.delete("location", location.id);
      • List<Tag> getTags(recordType, recordId)
        • Returns all tags assigned with a record.  You will most likely be interested in the name attribute of the Tag objects in the result list.  
        • Example: var tags = infoplusApi.getTags("order", order.orderNo);
      • void addTag(recordType, recordId, tag)
        • Adds a tag to a record.
        • Example: infoplusApi.addTag("order", order.orderNo, "my-special-orders");
      • void deleteTag(recordType, recordId, tag)
        • Deletes a tag from a record.
        • Example: infoplusApi.deleteTag("order", order.orderNo, "my-orders-on-hold");
      • void addAudit(recordType, recordId, auditMessage)
        • Adds an Audit to a record
        • Example: infoplusApi.addAudit("order", order.orderNo, "My script is making a certain decision about this order.");
  • utils
    • This object provides the following utility methods to Scripts:
      • void log (message) 
        • generates a log message that can be seen in the Output field of the Script Log that is created when the Script executes. Note that any particular run or execution of a script is limited to 100 KB of logs. If a script attempts to log more data than this, it will generate a runtime error.
        • Example: utils.log("Updated order [" + order.orderNo +"] priority code to [" + order.priorityCode + "]");
      • List<recordModel> fullSearch (infoplusApi, recordType, filter [, sort])
        • Calls the search method on the infoplusApi object in a loop, to fetch all pages of records matching the provided filter for the specified recordType.  This is a shortcut to avoid having to implement pagination directly in your script.  Note that the 4th parameter (sort) is optional.  See the search method on the infoplusApi object above for more details.  

        • Example:  var itemList = utils.fullSearch(infoplusApi, "item", "sku like 'A%' and status eq 'Active'");

      • httpResponseObject httpRequest(httpRequestObject)
        • Executes an HTTP request, using the values provided in the httpRequestObject, returning an httpResponseObject.  The fields on these objects are as follows:
          • httpRequestObject
            • method - String.  Required.  One of GET, POST, PUT, or DELETE.  This field defines the HTTP request method to be used.  
            • url - String.  Required.  Full URL to issue the request to.  
            • body - String.  Conditional.  Full string body content of the request to be sent to the specified URL (i.e., for POST or PUT requests).
            • headers - Array of Strings.  Optional.  Each string should be formatted as "Key:  Value", for example, "Content-Type: application/json"
          • httpResponseObject
            • statusCode - Integer.  Indicates the HTTP response code returned by the server (e.g., 200, 401, 503, etc)
            • body - String.  Full response body content returned from the server. 
            • headers - Object (map).  Name/Value pairs of all HTTP response headers returned from the server.  
        • Example:  
          • var httpPostResponse = utils.httpRequest({
            "method": "POST",
            "body": 'Duis posuere augue vel cursus pharetra.',
            "url": "https://postman-echo.com/post",
            "headers": [ "Content-Type: text/plain", "API-Key: myapikey" ]
            });
      • There are additional functions available on the utils object, depending on the script type used.  See this article on the utils function for more details. 

Run a Record Type Script Automatically by Using a Trigger

A Script can be run as a Trigger by adding an action of "Run Script" to a Trigger. See Triggers for more information.

  1.  When creating the action for the Trigger, you will first click on the number that appears in the Actions column for the trigger.

     
  2. From the drop-down menu, select Create New. The Create Action window appears.


     
  3. For the Action Type, choose "Run Script".

  4. Choose the Script to be associated with the Trigger.

  5. Click Save.

An example might be running a script to view data from the Item Serial Table. You can view how to set up that specific script here. 

Run a Script Manually from the Script Table

A Script can be run manually from the Script table, as well as from the Run Script process as described later. This can be used for testing a new Script, or to run a Script against a particular Record.

  1. In Infoplus, go to the Script table. Two ways:
    - From the DashboardClick the “Account Management” tab, click the “Scripts” App, then click the “Script” Table.
    - From the Quick Actions shortcut: Press a dot (period) on your keyboard, then select “Script” from the list of Quick Actions.

  2. Click the checkbox next to the Script you want to run. Also take note of the Record type needed for the Script.

  3. From the Actions menu, select Run Script.

  4. The Setup screen appears.



  5. Enter the Record Id of the Record on which the Script will operate. Be sure that the Record Type matches what was specified when the Script was created. The Record Type is visible within the Script table, as shown above.

  6. Click Next. The Review screen appears.

  7. Review the planned results. If acceptable, click Submit to run the script. The Results screen appears.


     
  8. Click OK to continue.

Run a Script Manually using the Run Script Process

A Script can be run manually with the Run Script process, as well as from the Script table as described above. This can be used for testing a new Script, or to run a Script against a particular Record.

  1. In Infoplus, access the Run Script process. Two ways:
    - From the DashboardClick the “Account Management” tab, click the “Scripts” App, then click the “Run Script” Process.
    - From the Quick Actions shortcut: Press a dot (period) on your keyboard, then select “Run Script” from the list of Quick Actions.
     
  2. Click the checkbox next to the Script you want to run. Also take note of the Record type needed for the Script.

  3. Click Next. The Setup screen appears.



  4. Enter the Record Id of the Record on which the Script will operate. Be sure that the Record Type matches what was specified when the Script was created. The Record Type is visible within the Run Script listing, as shown above.

  5. Click Next. The Review screen appears.



  6. Review the planned results. If acceptable, click Submit to run the script. The Results screen appears.



     
  7. Click OK to continue. 

Review Script Logs

Every time a Script runs, it generates a record in the Script Log table of Infoplus. This record contains the following fields:

  • Script - a reference to the Script that generated the Script Log.
  • Run Mode - an indication of how the Script was executed (either as a Trigger or a Manual Run).
  • Record Id - the id of the Record which was passed into the Script, if applicable.  
  • Had Error - an indication of whether or not the Script exited with an error or not.
  • Output - all logging output produced by the Script (via the utils.log method).
  • Errors - any errors encountered while executing the Script (including syntax errors, undefined references, Infoplus runtime errors, or exceptions thrown within the Script's source code).  
  • Run Time (ms) - the total runtime of the script, in milliseconds. Note that Infoplus may terminate a Script if it runs for longer than 60 seconds (or other limits configured on the Infoplus backend).  

Follow These Steps to See the Log for a Particular Script: 

  1. In Infoplus, go to the Script Log table. Two ways:
    - From the DashboardClick the “Account Management” tab, click the “Scripts” App, then click the “Script Log” Table.
    - From the Quick Actions shortcut: Press a dot (period) on your keyboard, then select “Script Log” from the list of Quick Actions.

  2. You may query the Script Log table by the specific Script you are investigating, or by the date of the script execution, or any other fields available on the Script Log table.  
  3. Click on the Log record that you want to view. 

Specific Script Types

Record

This is the original, and most generic type of Script available in Infoplus.  These scripts are called “Record” type scripts, because they run “against” a particular record.  That is to say, they receive 1 record from Infoplus as their input.  This record is made available by the global variable named record (it is also available by the name of the record’s type, for example, order or item).

A record type script can be ran:

  • As an action for a Trigger.  In this case, the record that was inserted or updated, which matched the Trigger’s Smart Filter is passed into the script as the input record.  

  • From any table query screen in Infoplus, via the Bulk Run Script option in the Actions menu.  In this case, the script will be ran once against all selected records from the table. 

  • From the Run Script option in the Actions menu when Viewing any record in Infoplus, in which case, the record being viewed will be passed in as the input record.

  • From the Script table’s Run Script action, where you will be prompted for the Id of the record that you want to run against the script (for example, that’s the Order No, for a script against the order table, and the Id for most other records in Infoplus).  Note that this usage is typically used while developing a script, to test and debug it.  

  • Using a Script Plan - where you select a script, and a smart filter against that script’s table, then can create a Scheduled Plan to execute that Script plan on whatever schedules you need. 

For some sample Record scripts, see:

Report

A report type script is used to customize the data in a User Report that is generated from Infoplus.  

For example, you can add or remove rows to a report, add columns to a report, or re-sort your report (i.e., change the ordering of the rows). 


See Using an Infoplus Script to Customize a User Report for more information on Report scripts, and for sample Report scripts, see:

Cartonization

A cartonization type script can be used to allow you to customize how cartonization is computed by Infoplus, by allowing you to control what carton types are used, or by allowing you to completely generate your own cartonization plan.  See Customizing Cartonization Using Scripts for more information on Cartonization scripts.

EDI

EDI type scripts allow you to customize your EDI document mappings.  For example, extracting different values from an inbound EDI document and storing that value in Infoplus, or taking customized values from Infoplus and placing them into an outbound EDI document.  

See the following articles for more information on EDI scripts:  

Email Template

Using an email template type script, you can customize the data that can be included in Custom Email Template, generated by Infoplus.  See Using Scripts on Custom Emails Templates for more information on Email Template scripts. 

External Shipping System

An External Shipping System script can be used to customize the data that Infoplus sends to an External Shipping System (e.g., ShipStation).  For example, you can pass data from Infoplus into a ShipStation custom field.  See Connect Infoplus to ShipStation and Send/Remove Orders for more information about External Shipping Systems.

Invoice Worksheet

To customize Invoice Worksheets produced as part of Infoplus’s 3PL Billing Module, you can use an Invoice Worksheet type script.  These scripts allow you to customize the Lines of an Invoice Worksheet as it is being generated by Infoplus.  

For some sample Invoice Worksheet scripts, see:

Manifest

A Manifest script can be used to customize the API call that Infoplus makes to our parcel manifesting partners when generating parcel labels for orders.  You can use this type of script to add accessories to shipments or adjust data on a label.  See Customizing Manifest Calls Using Scripts for more information on Manifest scripts.

Shopping Cart Connection Order

During the process of importing an order from a Shopping Cart Connection, Infoplus can run a shopping cart connect order type script, to allow you to inject some custom logic into the order import process.  For example, you can edit the data that Infoplus has received from the shopping cart, or you can tell Infoplus to reject the order, based on your custom needs.  

For some sample Shopping Cart Connection Order scripts, see:

Smart Document

Using a smart document type script, you can customize the data that can be included in a Smart Document Template.  In other words, you can look up additional data, or apply custom logic, to customize the documents you produce from Infoplus.  See Create and use Smart Document Templates for more information about Smart Document Templates.  

Warehouse Apps Input

The latest generation of Infoplus warehouse operation apps allow you to inject custom logic to your warehouse scans, through a warehouse apps input script.  For example, if you have barcodes with additional data on them, and you need to strip that data away before it gets into Infoplus, this type of script can do just that.  See Using an Infoplus Script to Customize Warehouse Apps Input for more information on Warehouse Apps Input scripts.  

Warehouse Document

Some of the warehouse documents produced by Infoplus (e.g., Work tickets) can have some of their contents modified by using a warehouse document type script.  See Warehouse Document Scripts for more information on Warehouse Document scripts.