Script to capture order confirmation page requested for field value
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-18-2024 02:06 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-18-2024 02:14 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-18-2024 07:05 AM
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.