- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-09-2023 11:07 PM
Hello Community members,
I am learning scripting in ServiceNow & stuck in setting condition to check whether the 'Caller (caller_id)' of respective incident is 'VIP' or Not, if 'VIP' then display a field msg. on 'Form View of Agent Workspace'. if false (i.e., Not VIP) then no need to Display the VIP field msg.
For this, created an onload CS on Incident table, View- workspace (Global-false), UI type- All, Isolated script- check,
Script-
function onLoad() {
//Type appropriate comment here, and begin script below
g_form.showFieldMsg('caller_id','VIP','info');
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-09-2023 11:34 PM - edited ‎02-09-2023 11:37 PM
Hi @rishabh31 ,
Try the below script. This should server your purpose:
g_form.getReference("caller_id",checkIfVIP);
function checkIfVIP(user){
if(user.vip == "true")
g_form.showFieldMsg("caller_id","This user is a VIP user","info") //Change your field msg content
else
g_form.hideFieldMsg("caller_id")
}
I hope this helps.
Please hit Helpful if this helps you and Accept the response if this solves your issue.
Regards,
Kamlesh

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-09-2023 11:13 PM
Hi @rishabh31 ,
do like this
var caller = g_form.getValue("caller_id");
if(caller == "VIP"){
g_form.showFieldMsg('caller_id','VIP','info');
}
else
{
g_form.showFieldMsg('caller_id','Not VIP','info');
}
Please mark correct if my response has solved your query.
Cheers,
Mohammed Basheer Ahmed.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-09-2023 11:21 PM
Hi Rishabh,
Please try this-
function onLoad() {
// Get the value of the caller_id field
var caller_id = g_form.getValue('caller_id');
// Check if the caller_id is equal to 'VIP'
if (caller_id === 'VIP') {
// Show the field message if the caller_id is 'VIP'
g_form.showFieldMsg('caller_id','VIP','info');
}
}
In this script, the g_form.getValue('caller_id') method is used to get the value of the caller_id field. The value is then compared to the string 'VIP' in the if statement to determine whether the Caller is a VIP or not. If the Caller is a VIP, the g_form.showFieldMsg('caller_id','VIP','info') method is used to display the field message on the form.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-09-2023 11:34 PM - edited ‎02-09-2023 11:37 PM
Hi @rishabh31 ,
Try the below script. This should server your purpose:
g_form.getReference("caller_id",checkIfVIP);
function checkIfVIP(user){
if(user.vip == "true")
g_form.showFieldMsg("caller_id","This user is a VIP user","info") //Change your field msg content
else
g_form.hideFieldMsg("caller_id")
}
I hope this helps.
Please hit Helpful if this helps you and Accept the response if this solves your issue.
Regards,
Kamlesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-10-2023 02:01 AM
@kamlesh kjmar , Thanks Sir🙂, It works fine, just applied a semicolon on g_form.showFieldMsg & g_form.hideFieldMsg.
@Amit Pandey @kamlesh kjmar @Basheer @shyamkumar VK Sir, to apply the background colour on the caller field for List view of agent workspace, created another post by following below URL, requesting you all to please have a look at this URL for details & help me to get this done, shall be highly grateful to you all.
This ask is solved so Marked as Accepted solution & Helpful! Thanks once again