The CreatorCon Call for Content is officially open! Get started here.

Client Script Help.

Steven_4rcher
Tera Contributor

Hi All,

 

I have been tasked with creating an alert (or not) on load and on change.

 Under the Restaurant Field:

Steven_4rcher_0-1754992351408.png

I would like an alert that references another field in the Location information. I have the following:

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
   if (isLoading || newValue === '') {
      return;
   }

   //Type appropriate comment here, and begin script below
 
g_form.showFieldMsg('u_restaurant', 'Current Trial:'  + ' ' + getValue('u_restaurant.u_choice_3'), 'info');

}
 
but this is returning 'Null'
Steven_4rcher_1-1754992514022.png

 

I'm not trained in SNow and pretty much wing it with the help of community articles and google, but this time i cannot see a solution.

 

thanks in advance

 
1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@Steven_4rcher 

if u_choice_3 is a field in the table being referred by Restaurant field then this script will work

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading) {
        return;
    }

    g_form.hideFieldMsg('u_restaurant');

    var ref = g_form.getReference('u_restaurant', callBackMethod);
}

function callBackMethod(ref) {
    if (ref.u_choice_3)
        g_form.showFieldMsg('u_restaurant', 'Current Trial:' + ' ' + ref.u_choice_3, 'info');
}

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

View solution in original post

4 REPLIES 4

Rafael Batistot
Kilo Patron

Hi @Steven_4rcher 

 

May you try this

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || !newValue) {
return;
}

var trialValue = g_form.getValue('u_choice_3');

g_form.clearMessages();
g_form.showFieldMsg('u_restaurant', 'Current Trial: ' + trialValue, 'info');
}

If you found this response helpful, please mark it as Helpful. If it fully answered your question, consider marking it as Correct. Doing so helps other users find accurate and useful information more easily.

thanks for the prompt reply, This unfortunately returned nothing.

maybe i should have mentioned the U_Restaurant field on the Incident table references the 'location' table. U_Choice_3 is a field in the location table:

Steven_4rcher_0-1754994005715.png

 

I edited your script to return just the u_Restaurant field (I figured if i could get it to mimic the restaurant field i could work from there)

 

var trialValue = g_form.getValue('u_Restaurant');

and the message returned:

Steven_4rcher_1-1754994185732.png

 

Ankur Bawiskar
Tera Patron
Tera Patron

@Steven_4rcher 

if u_choice_3 is a field in the table being referred by Restaurant field then this script will work

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading) {
        return;
    }

    g_form.hideFieldMsg('u_restaurant');

    var ref = g_form.getReference('u_restaurant', callBackMethod);
}

function callBackMethod(ref) {
    if (ref.u_choice_3)
        g_form.showFieldMsg('u_restaurant', 'Current Trial:' + ' ' + ref.u_choice_3, 'info');
}

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

My hero