Configuring and Using the Script Object

In this section:

How to:

The Script object is available, which you can configure and add to process 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 process 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 process flow. As a result, you can also reuse identical logic across multiple systems.

To add the Script object to a process flow, click and drag the Script object from the Execution Objects palette, as shown in the following image.

You can also add the Script object to a process flow from the New Object Wizard dialog, as shown in the following image.

Procedure: How to Add a Script Object to a Process Flow

  1. Click and drag the Script object from the Execution Objects palette to your process flow, as shown in the following image.

    You can also right-click anywhere in the workspace area and select Create Object from the context menu.

    From the New Object Wizard dialog that opens, expand the Execution Objects category and select the Script object, as shown in the following image.

  2. Click Next.

    The New Script Object dialog opens, as shown in the following image.

  3. Enter a name (required) and a description (optional) for the Script object, and then click Next.

    The Object Properties pane opens, as shown in the following image.

  4. Type the path to a valid script file on your file system in the Script File field, and click Finish.

    Note: You can also click Next to enter pre-execution variables, post-execution variables, and set debug settings for this object if required.

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

  5. Add an End object and create the appropriate connections between the objects as required.

Example 1: Invoking a Process Flow and Service

How to:

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

Procedure: How to Invoke a Process 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 process flow and add a Script object that points to the following path:
    C:\Scripts\pflowobj.js

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

  4. Import the hello_p1 process flow from the sample hellozos.zip archive using the Archive Manager tool in the iSM Administration Console.
  5. Export the hello_p1 process flow to an Integration Project.
  6. Create a new application by adding the new process flow (containing the Script object) and the imported hello_p1 process flow.
  7. Test run the new process 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

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 process flow and add a Script object that points to the following path:
    C:\Scripts\transformobj.js

    This process 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 Integration 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 Integration 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 process flow (containing the Script object) and the imported sample iWay Transform project.
  7. Right-click the process flow, select Run As, and then Run Configurations from the context menu.
  8. Test run the new process 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.


iWay Software