Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Script to capture order confirmation page requested for field value

BanuMahalakshmi
Tera Contributor

Hi,

 

i logged in a system admin profile, i changed the requested for value as "Adela cervantsa".

Pls assist the script to get requested for value from the order confirmation page. Thanks.

 

BanuMahalakshmi_0-1726649736936.png

 

2 REPLIES 2

rajan_singh
Tera Contributor

To capture the "requested for" field value from the order confirmation page in ServiceNow, you can create a Client Script. Below are the steps to achieve this:

1. Navigate to Client Scripts:
- Go to System Definition > Client Scripts.

2. Create a New Client Script:
- Click on 'New' to create a new Client Script.
- Fill in the details:
- Name: Capture Requested For
- Table: Select the appropriate table, e.g., `sc_request` or `sc_req_item`.
- Type: OnLoad
- Active: True

3. Add the Script:
- Use the following JavaScript code in the script field:

 (function() {
         // Ensure the script runs only on the order confirmation page
         if (g_form.getTableName() === 'sc_request' || g_form.getTableName() === 'sc_req_item') {
             // Get the 'requested for' field value
             var requestedFor = g_form.getValue('requested_for');
gs.info('Requested For: ' + requestedFor);
         }
     })();

This script checks if the current table is `sc_request` or `sc_req_item` and then retrieves the value of the "requested for" field. Adjust the table name and field name according to your specific instance configuration.

Thanks for reply, I have tried the above script but it print the Null value. it didnt fetch the requested for value which i selected into Order confirmation page.