Configuring and Using the Script Object

Topics:

How to:

The Script object is available, which you can configure and add to flows that are constructed in iIT. The Script object uses the following iSM service type:

com.iwaysoftware.service.ScriptAgent

The Script object allows you to include complex document processing and routing instructions in your flow that are written in any scripting language that is supported by the Java Scripting API (for example, Jython). This enables your application to optimize some of the application processing into a script rather than a complex flow. As a result, you can also reuse identical logic across multiple systems.

To add the Script object to a flow, click and drag the Script object from the Components section of the Palette, as shown in the following image.

Procedure: How to Add a Script Object to a Flow

  1. Click and drag the Script object from the Components section of the Palette to your flow, as shown in the following image.

    The new Script object is added to the workspace area, as shown in the following image.

  2. In the Name field of the Properties pane, enter the a full path to the script file, which should include an explicit location, such as c:\myscripts\myscript.jsscript, or click the ellipsis (...) and navigate it, as shown in the following image.
  3. Click the Start object, select the Create path link, and drag it to the Script object, as shown in the following image.
  4. Similarly, click the Script object, select the Create path link, and drag it to the End object.
  5. Delete the original path between the Start and End objects.

    The Script object is now in the flow between the Start and End objects, as shown in the following image.

Example 1: Invoking a Flow and Service Using the Script Object

How to:

This example shows how a flow and service can be invoked using the Script object.

Procedure: How to Invoke a Flow and Service

  1. Create a file called pflowobj.js on your file system that contains the following JavaScript code:
    importPackage(com.ibi.edaqm);
    importPackage(com.iwaysoftware.iwscript);
    function execute() 
    {
    var outDir = tools.getSpecialRegister("docOut");
    params = tools.newParameters();
    params.put("directory", outDir);
    // execute process
    processName = "hello_p1";
    process = tools.getProcess(processName);
    processResponse = new XDDocument();
    state = process.execute(ctx.getDocIn(), processResponse);
    if (state.indexOf('fail') == 0) 
    {
    tools.info("Process flow '" + processName + "' not found");
    } 
    else
    {
    // write result of process to file
    params.put("pattern", "process.xml");
    processToFile = tools.makeNewService("XDFileEmitAgent", params);
    processToFile.execute(processResponse, new XDDocument());
    return "success";
    }
    }
  2. Save this file to a location on your file system (for example, C:\Scripts).
  3. Create a new flow and add a Script object that points to the following path:
    C:\Scripts\pflowobj.js

    This flow must contain a Start object, Script object, and an End object.

  4. Import the hello_p1 flow from the sample hellozos.zip archive using the Archive Manager tool in the iSM Administration Console.
  5. Export the hello_p1 flow to an Application Project.
  6. Create a new application by adding the new flow (containing the Script object) and the imported hello_p1 flow.
  7. Test run the new flow (containing the Script object) against the test server. Ensure that the new application is added to the Test Server tab.

    Verify that a response is obtained in the destination as defined by the new application.

Example 2: Invoking an iWay Transform Component Using the Script Object

How to:

This example shows how an iWay Transform component can be invoked using the Script object.

Procedure: How to Invoke an iWay Transform Component

  1. Create a file called transformobj.js on your file system that contains the following JavaScript code:
    importPackage(com.ibi.edaqm);
    importPackage(com.iwaysoftware.iwscript);
    function execute() 
    {
    transformResult = new XDDocument();
    transform = tools.getTransform("Computer_Parts_Sales");
    status = transform.execute(ctx.getDocIn(), transformResult);
    return XDAgent.EX_SUCCESS;
    }
  2. Save this file to a location on your file system (for example, C:\Scripts).
  3. Create a new flow and add a Script object that points to the following path:
    C:\Scripts\transformobj.js

    This flow must contain a Start object, Script object, and an End object.

  4. Import the following sample iWay Transform project into the Transforms subfolder of your Application Project:
    <ism_home>\tools\transformer\samples\transform_projects\xml\XML_to_XML\Computer_Parts_Sales
  5. Import the following sample input XML document into the XML subfolder of your Application Project:
    <ism_home>\tools\transformer\samples\transform_projects\xml\XML_to_XML\Computer_Parts_Sales\input.xml
  6. Create a new application by adding the new flow (containing the Script object) and the imported sample iWay Transform project.
  7. Right-click the flow, select Run As, and then Run Configurations from the context menu.
  8. Test run the new flow (containing the Script object) against the test server. Ensure that the new application is added to the Test Server tab.
  9. Return to the main tab and select the input. Select Use Test Server and click Run.

    Verify that a response is obtained in the destination as defined by the new application.