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

Populate the field info message

DeepikaR1661877
Tera Contributor

Hi All,

There is one requirement in incident table when category is "Dev" and subcategory is "Test" then i want populate the info message under the subcategory field(Based upon the subcategory is depend field of category) So i have created the one onchange client script,  it's not working i have try to get the value by using the console, even i didn't get, any one help on this part?

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
   if (isLoading || newValue === '') {
      return;
   }
    var category = g_form.getValue('category');
alert('checking' + g_form.getValue('category'));
    var subcategory = g_form.getValue('subcategory');
    if (category === 'Dev' && subcategory === 'Test') {
        g_form.addInfoMessage('Please proceed with caution while handling internal support investigations');
    } else {
        g_form.clearMessages();
    }
}
}
1 ACCEPTED SOLUTION

Hello @DeepikaR1661877 

  • No, You cannot populate link using g_form.showfieldmsg().
  • The g_form.showFieldMsg() method is primarily used to display messages (such as error, warning, or informational messages) below a field.

Hope this helps!

 

"If you found my answer helpful, please like and mark it as an "accepted solution". It helps future readers to locate the solution easily and supports the community!"

 

Thank You
Juhi Poddar

View solution in original post

20 REPLIES 20

NagaChandaE
Kilo Sage

Hi @DeepikaR1661877 

Write this script on onChange client script on subcategory field .

 

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

var category = g_form.getValue('category');

if (category == 'Dev' && newValue == 'Test') {
g_form.showFieldMsg('subcategory', 'This is a Test subcategory for Development', 'info');
} else {
g_form.hideFieldMsg('subcategory');
}
}

Ankur Bawiskar
Tera Patron
Tera Patron

@DeepikaR1661877 

Your script has an issue.

You should use == and not === during comparision

Also are you sure you are comparing the correct values for category and subcategory?

If yes then your script will work fine.

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

Hi @Ankur Bawiskar ,

I have one more doubt, can populated the link by using g_form.showfieldmsg ?

Hello @DeepikaR1661877 

  • No, You cannot populate link using g_form.showfieldmsg().
  • The g_form.showFieldMsg() method is primarily used to display messages (such as error, warning, or informational messages) below a field.

Hope this helps!

 

"If you found my answer helpful, please like and mark it as an "accepted solution". It helps future readers to locate the solution easily and supports the community!"

 

Thank You
Juhi Poddar

Juhi Poddar
Kilo Patron
Kilo Patron

Hello @DeepikaR1661877 

Try this onChange Client script:

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    // Avoid executing script during form load or if newValue is empty
    if (isLoading || newValue === '') {
        return;
    }
g_form.hideFieldMsg('subcategory');
    // Get values of category and subcategory fields
    var subcategory = newValue; // Subcategory field's new value
  alert('Subcategory: ' + subcategory); // Debugging
    var category = g_form.getValue('category'); // Parent field
  alert('Category: ' + category); // Debugging

    // Check if category is 'Dev' and subcategory is 'Test'
    if (category === 'dev' && subcategory === 'test') { //update 'test' and 'dev' to backend value
       g_form.showFieldMsg('subcategory','Please proceed with caution while handling internal support investigations','info');
    } 
}

 

Note: Please update 'dev' and 'test' to the backend value of 'Dev' and 'Test' in script.

To get the backend value:

  • Right click on form label(Category/Subcategory)
  • Configure dictionary
  • Under related list -> choice section the value column holds the backend name.

Hope this helps!

 

"If you found my answer helpful, please like and mark it as an "accepted solution". It helps future readers to locate the solution easily and supports the community!"

 

Thank You
Juhi Poddar