OnLoad Client script help to setup condition

rishabh31
Mega Sage

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');
    }

 

 
Unable to find the correct condition which checks the caller of the respective incident in Agent workspace Form view is 'VIP' or not. I tried OOB on change the Client script condition to check VIP status but it did not work. Thus currently it shows VIP info msg for all the callers in form view for Agent workspace (screenshot attached)
 
Requesting community members to help me with the condition so that 'VIP' field msg. gets displayed to only VIP callers of Incidents not everyone (currently its displaying VIP for every users).
 
Will mark the solution as 'Helpful' once the same is resolved.
 
Requesting support, thanks
 
 
1 ACCEPTED SOLUTION

kamlesh kjmar
Mega Sage
Mega Sage

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

View solution in original post

5 REPLIES 5

shyamkumar VK
Kilo Patron

hello @rishabh31  ,

Allow client script to work on AGENT WORK SPACE FORM VIEW and add below code 

 

var caller = g_form.getReference('caller_id',callerinfo)// callerinfo is an callback function
function callerinfo(){

if(caller.vip==true){

g_form.showFieldMsg('caller_id','VIP','info');
}

else{

g_form.hideFieldMsg('caller_id')


}

}

 

Please mark this as helpful and accept as a solution if this resolves your Ask.
Regards,

Shyamkumar