I need to write a script to fill in a glide list with 3 values, assigned_to, caller and opened_by. Please see screenshot below.

dinasabry
Kilo Contributor

Hi,

I need to write a script to fill ina glide list with 3 values, assigned_to, caller and opened_by. Please see screenshot below. Should it be a client script, UI policy or what?  How do I access this glide_list (u_users_enabled_to_access_case)

find_real_file.png

1 ACCEPTED SOLUTION

This wouldn't work as a client script, as it is using current, which is in the server-side API. 

 

Can you post a screenshot of your business rule? It should be set to run Before. If you have it running After, it would not work, as there is nothing telling it to write to the database. Before business rules have an inherent "current.update()" after all Before BRs have completed. 

 

Also, make sure the field names are correct in the script. Are any of the values going into the GlideList field?

View solution in original post

12 REPLIES 12

Tim,

Thanks a million. That did it. Insert before.

Have a great day1!!

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hello Dinasabry,

 

Create a Before business rule insert/update (per your req) with the script as below. The below script will also take when u_users_enabled_to_access_case is already populated.

(function executeRule(current, previous /*null when async*/) {

// Add your code here
var u_users_enabled_to_access_case = current. u_users_enabled_to_access_case.toString().split(",");

if (u_users_enabled_to_access_case.toString().indexOf(current.caller_id) == -1) {
watch_list.push(current.caller_id);
}
if (u_users_enabled_to_access_case.toString().indexOf(gr.assigned_to) == -1) {
watch_list.push(current.assigned_to);
}
if (u_users_enabled_to_access_case.toString().indexOf(gr. opened_by) == -1) {
watch_list.push(current.opened_by);
}
current. u_users_enabled_to_access_case = u_users_enabled_to_access_case.join(",").toString();


})(current, previous);

 

Please let me know if you have any questions.

 

Thanks,

Pradeep Sharma

dinasabry
Kilo Contributor

Thank you! however, i have a quesiton. Why sometime you use current. and other times you use gr. ?

current is use to access the current record object where as gr i.e GlidRecord is used to access the other table record or another record of the same table.

I think in the script from Pradeep, any "gr" should be replaced with "current". I find myself frequently mixing the two up since they are very common object names in ServiceNow scripts.