Script help - adding a user to the Watch List based on the customer's company

Wayne Richmond
Tera Guru

Hi all - I've been trying to do this for over an hour now with my very limited scripting knowledge but it's frustrated me and still isn't working.

I am trying to add a user to the Watch List of an Incident if the customer's company is a particular value. I thought it was as simple as this but it isn't working (onChange Client Script):

var cust = g_form.getReference('caller_id');

if (cust.company = 'XYZ Company') {

g_form.setValue('watch_list', 'Anthony User');

}

When this didn't work I tried something with 'new GlideRecord' but that's me way out of my depth! Can anyone help wit this please?

Thank you

1 ACCEPTED SOLUTION

Abhinandan Pati
Giga Guru

Hi Wayne,



Why did you choose onChange Client Script? Could you please elaborate what are you trying to achieve here?



I think it will be better if you implement this operation using   'Before Insert & Update' Business Rule.



You can try something like this



if(current.caller_d.company==<Mention Company Name here>){


current.watch_list=current.caller_id;


}



Thanks


Abhinandan


View solution in original post

4 REPLIES 4

Abhinandan Pati
Giga Guru

Hi Wayne,



Why did you choose onChange Client Script? Could you please elaborate what are you trying to achieve here?



I think it will be better if you implement this operation using   'Before Insert & Update' Business Rule.



You can try something like this



if(current.caller_d.company==<Mention Company Name here>){


current.watch_list=current.caller_id;


}



Thanks


Abhinandan


Thanks Abhinandan, this is a much simpler solution. The idea of using a Client Script was to give the call logger the option to remove it but I don't think that's a requirement anyway.


simonw
Tera Expert

Hi Wayne,



You're on the right track with your script however you'll need to provide the reference to the user you want to add to the watch list.   So if you're doing this client side, you'd need to lookup the sys_id for Anthony User



As a suggestion, you could make this generic and add a default watch list field on your company table.   You could then use the code below to always copy the watch list across



var strWatchList = company.u_default_watch_list.toString();


  if (strWatchList != '') {


  g_form.setValue('watch_list', strWatchList);


  }



Kind regards,



Simon


vaibhavdesai
Kilo Expert

Hello Wayne,



Instead of doing onChange Script. Try to do onSubmit script.



Sample.



function onSubmit(){


var cust = g_form.getReference('u_requester');  


  alert(cust.company);


if (cust.company = 'XYZ Company') {  


  alert("Inside IF");


g_form.setValue('watch_list', 'Wayne Richmond');  


}


}



FYI:- You can directly add name of your user it will work(if you spell it correctly). But,Best practice is to use "sys_id" instead of name whenever you are using reference.



Regards,


Vaibhav



P.S:- Mark this answer as helpful or Correct accordingly.