How to Pre-Populate Fields Based on JavaScript Expressions

When you use an element that includes the value attribute as a field on a form, you can use a JavaScript expression to pre-populate the element's value attribute with the runtime value of one of many objects and properties from the CA Service Catalog database.

For example, in the text field for First Name on your form, you could specify the JavaScript expression $(_.user.firstName) to pre-populate the field with the first name of the logged in user ID who is creating the request and completing the form. Similarly, in the text field for Last Name, you could specify the JavaScript expression $(_.user.lastName) to pre-populate the field with the user's last name.

To pre-populate fields on forms using JavaScript expressions, follow this process:

  1. Design and create the form.
  2. Verify that the best way to perform the automated task in the field or fields of interest is to use a JavaScript expression.
  3. Review the guidelines for using JavaScript expressions in fields and verify that you want to pre-populate the value attribute of an element in the field.
  4. Verify that the data that you want to pre-populate is one of the objects and properties that you can specify in JavaScript expressions. These objects and properties are related to the logged in user's personnel data, to one or more business units, or to service, service options, status, or other data related to the request that contains the form.
  5. Specify the JavaScript expression in the value attribute of the element for the field. When specifying the expression, follow all syntax rules in objects and properties that you can specify in JavaScript expressions, especially the rules related to using operators to link properties. The following are some valid expressions that you may find useful as-is or as models:
  6. Test the JavaScript expression to verify that it accomplishes your goals for pre-populating the field on the form.
  7. As a best practice, verify that you test the expression in a form used with a service in a test environment before you use the form and the service in a production environment.