Open topic with navigation

TIBCO Business Studio™ - BPM Edition 5.4.0

# Working with Temporary Variables and Types

When writing scripts, the need for temporary variables often arises. In JavaScript, a temporary variable is declared using the `var` keyword. This saves having to add all variables as Process Data Fields, which is especially useful if the variables are only used within a single script. Adding them to the list of Data Fields would just end up complicating the process.

For example, to declare (that is, to tell the script engine about) two temporary variables called `x` and `carName` you can write:

    var x;
    var carName;

The variables can also be initialized (given initial values) when they are declared like this:

    var x = 5;
    var carName = "Herbie";

When writing BPM scripts, it is always best to initialize variables when they are declared so that TIBCO Business Studio’s Script Validation and Content Assist code knows what are the types of variables. If you do not initialize a variable, you get the following warnings:

Unable to determine type, operation might not be supported and content assist might not be available

The content assist does not work. So, using the example from the previous section, it would not be a good idea to write:

    var c1;
    var c2;
    c1 = factory.com_example_data.createCustomer();
    data.c1.name = "Fred Blogs";
    data.c1.custNumber = "C123456";
    custList.push(c1);
    c2 = factory.com_example_data.createCustomer();
    data.c2.name = "John Smith";
    data.c2.custNumber = "C123457";
    custList.push(c2);

Instead, the variables should be initialized when they are declared:

    var c1 = factory.com_example_data.createCustomer();
    data.c1.name = "Fred Blogs";
    data.c1.custNumber = "C123456";
    custList.push(c1);
    var c2 = factory.com_example_data.createCustomer();
    data.c2.name = "John Smith";
    data.c2.custNumber = "C123457";
    custList.push(c2);

Did you find this helpful?

Yes No
Great!
Thanks for taking the time to give us some feedback.
Sorry about that

Why wasn't this helpful? (check all that apply)

Could not find what I was looking for
Instructions confusing or unclear
Instructions did not work

Want to tell us more?

Please select at least one option or provide details about the issue!!

Error occurred while submitting feedback.

Error2 occurred while submitting feedback.

TIBCO Business Studio™ - BPM Edition

Copyright © 2015-2023. Cloud Software Group, Inc. All Rights Reserved.