Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

onLoad client script to display field message on Html Variable type

Trupti Krishnam
Tera Contributor

I need to write an onload client Script on a HTML type variable called 'what would you like to do '

and the message is : -

Which department ? 
Has been identified and secured?
If so, which FY and/or future periods available?

 

i've tried it in the below way 

 g_form.showFieldMsg("u_v_todo ", "Which department?
        Has been identified and secured ?
        If so, which FY and / or future periods available ? );
}
 
it is not working can anyone help please !
1 ACCEPTED SOLUTION

@Trupti Krishnam Create one variable of type "Rich Text Label" and place it after your HTML variable as below..

JSiva_0-1755173138286.png

JSiva_1-1755173171442.png

 

View solution in original post

14 REPLIES 14

@Trupti Krishnam 

Ok then asa  workaround create one more HTML variable and put the message there. Then make the field read-only.

Use one on load client script to hide the label of the new created HTML field.

It worked for me in PDI:

 

g_form.showFieldMsg("u_v_todo", "Which department?");
g_form.showFieldMsg("u_v_todo","Has been identified and secured ?");
g_form.showFieldMsg("u_v_todo","If so, which FY and / or future periods available ?");

Raghav
MVP 2023
LinkedIn

Shashank_Jain
Kilo Sage

@Trupti Krishnam , Try this code it will work -

function onLoad() {
    var message = "Which department?<br>" +
                  "Has been identified and secured?<br>" +
                  "If so, which FY and/or future periods available?";
    
    g_form.setValue('u_v_todo', message);
}

 

I tried it on PDI and it work!

Screenshot (13).png

If this works, please mark it as helpful/accepted — it keeps me motivated and helps others find solutions.
Shashank Jain

i should not set the msg it should appear as an info msg right below the html variable type

@Trupti Krishnam , Try this 

Just update your variable name instead of 'u_test_script'

function onLoad() {
    var htmlVar = g_form.getControl('u_test_script');
    if (!htmlVar) return; // Safety check

    // Create the info message element
    var msgContainer = document.createElement('div');
    msgContainer.className = 'fieldmsg notification notification-info';
    msgContainer.style.marginTop = '5px';
    msgContainer.innerHTML =
        'Which department?<br>' +
        'Has been identified and secured?<br>' +
        'If so, which FY and/or future periods available?';

    // Insert right after the HTML variable
    htmlVar.parentNode.appendChild(msgContainer);
}


 

Refer the below screenshot, Is this what you trying to do?

Screenshot (14).png

If this works, please mark it as helpful/accepted — it keeps me motivated and helps others find solutions.
Shashank Jain