Get value of a field in client script without form saving
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-15-2025 03:22 AM
I have created two on change client scripts , on change of a caller, priority should get change and form should not get save. Now I want the value of that priority in another client script and show on info messge. How will I achieve this ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-15-2025 07:26 AM
Hi @KritikaS3501173 ,
I think it is achievable from one client script. For example, onChange of caller, set priority = 1 - High and display an info message from one client script.
If my response helped you, please click on "Accept as solution" and mark it as helpful.
- Saloni
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-15-2025 08:07 AM
you cannot stop form from saving within onChange client script.
1st client script on Change of caller
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue === '') {
return;
}
// Change the priority based on the caller
g_form.setValue('priority', '2'); // Example: setting priority to 2
}
Then another client script on change of priority to show info message
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue === '') {
return;
}
// Retrieve the priority value
var priority = g_form.getValue('priority');
// Show the priority value in an info message
g_form.addInfoMessage('The current priority is: ' + priority);
}
another onSubmit to stop form submission
function onSubmit(){
return false;
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-15-2025 08:09 AM
Hello @KritikaS3501173, you can configure your Client script to run on change of Priority and display a message. It should be an easy one, something like below:
I assume that you have taken care of changing the Priority based on Caller field change, if not then you can reset the impact and urgency in client script that will change the priority automatically. Surely, there should be a logic of setting the priority that you can take care of. Below is just an example of resetting the priority:
g_form.setValue('impact', '2');
g_form.setValue('urgency', '2');
Regards,
Nishant