Previous Topic: How to Use JavaScript Expressions in Fields

Next Topic: How to Pre-Populate Fields Based on JavaScript Expressions


Objects and Properties that You Can Specify in JavaScript Expressions

You specify objects and properties in JavaScript expressions. You can use these expressions for the runtime values of the value attribute for the elements that you use as fields on forms. Typically, you specify these expressions in the following format: $(_.object.property).

For example, to capture the runtime value of the logged in user completing the form in a request, specify $(_.user.firstName). You can also concatenate strings, as explained later in this topic.

These variables apply for Form Designer forms only! They are similar but are not the same as the objects and properties defined for CA Workflow forms variables. If you are using both Form Designer forms and CA Workflow forms, use the correct objects and properties for each type of form.

Forms

The form object contains the following property that you can use in JavaScript expressions or as a first parameter in JavaScript functions: ca_fd.formId.

formId refers to the active form. The form is in active when a field in the form triggers an event. The following are a few sample actions that activate forms:

User

The user object contains an array of user properties that you can access using _.user.

Each user object has the following properties, listed in related groups:

Examples

You can use the _.user.groups property to hide a field from members of a CA EEM group, for example, the group named developers. To do so, set the value of the HTML attribute named Hidden to the following:

_.user.groups.indexOf("developers") >= 0

In contrast, you can also make a field visible to users who are not members of a CA EEM group. To do so, set the value of the Hidden attribute to the following:

_.user.groups.indexOf("developers") < 0

Business Unit

The business unit object contains an array of business unit properties that you can access using _.bu.

Each business unit object has the following properties, listed in related groups:

Request

The request object contains an array of request properties that you can access using _.request.

Each request object has the following properties, listed in related groups:

Service

The service object contains an array of services that you can access using _.service.

Each service object has the following properties, listed in related groups:

Service Option Groups

The service option groups object contains an array of service options that you can be access using _.sog.name.

Each service option group has the following properties, listed in related groups:

Service Options

The service option object applies only to the predefined JavaScript function named _.serviceoption.status( ).

The _.serviceoption.status( ) function contains a single property, which is named newStatus.

Note: This function does not take any parameters.

newStatus--

Specifies the new value for the status when a user action updates the status of the service option. This property takes the new value for the status as soon as the user does one of the following:

In both cases, the value of _.serviceoption.newStatus() changes immediately. In contrast, the value of _.serviceoption.status( ) remains unchanged until the page is submitted and refreshed.

Note: JavaScript functions related to status changes do not change their behavior if they depend on the user completing the page or dialog. (Typically, this action is clicking OK). For example, the JavaScript function named onSubmit typically references status changes. The onSubmit function runs only when the user completes the page or dialog, not when the value of newStatus changes.

Examples

You can use the newStatus property to help your implementation process reservations efficiently. For example, suppose a user submits a main request for a computer and additional requests for related options. These options include extra memory, an upgraded keyboard, and so forth. You can create a custom JavaScript function so that if the main request is rejected, the onSubmit function runs for all optional requests. Examples of optional requests include accessories, extra memory, and so forth. For example, the following expression evaluates to True when the original status is 400 and the newStatus is changed to 800:

 if (_.serviceoption.status() == 400 && _.serviceoption.newStatus == 800)...

Operators

The operators most commonly used for form design are described here. For complete details about standard operators, see the JavaScript standards reference that your organization uses, for example, www.developers.sun.com, or www.javascript.com.

You can specify all standard operators in your JavaScript expression except assignment operators.

The assignment operators are as follows: =, +=, -=, *=, /= .

For example, the folowing expression is invalid because it uses the = assignment operator:

$(var x = 1+2)

Required Return Values

Specify JavaScript expressions for the disabled, checked, and hidden attributes that return one of the following values:

If the expression returns any other value, CA Service Catalog replaces it with a value of false. Therefore, if you specify $(_.user.firstName) for the disabled attribute of a text field, the field is not disabled unless "true" is the first name of the user.

Concatenation Operators

You can optionally concatenate two strings together, using the + operator,

For example, $(‘Hello ‘ + _.user.firstName + ‘ ‘ + _.user.lastName) returns the following text: Hello first-name last-name. "Hello John Doe" and "Hello Jane Smith" are samples.

Comparison Operators

You can optionally use the following comparison operators:

For examples used in the Form Designer, see the topics for the following:

Logical Operators

You can optionally use the following logical operators:

For examples used in the Form Designer, see the topics for the following: