Get value of a field in client script without form saving

KritikaS3501173
Tera Contributor

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 ?

3 REPLIES 3

Saloni Suthar
Mega Sage
Mega Sage

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

Ankur Bawiskar
Tera Patron
Tera Patron

@KritikaS3501173 

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.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Nishant8
Giga Sage

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:

Nishant8_0-1744729477493.png

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