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.

Business Rule Script to Update Another Table

jmiskey
Kilo Sage

We have a custom application named "Desktop Services".   Within that, we have a table named "Desktop Services Table", which is an extension of the Task table.

To the "State" field, we added a custom choice option of "Never Hired".   I would like to add a Business Rule that does the following:

When the State field is set to "Never Hired", the following changes should happen to the User record that this Desktop Services task is for:

- Update the Term Date field (u_term_date) to match the value in the Last Hire Date field (u_hire_date)

- Uncheck the "active" checkbox

- Check the "term ticket generated" (u_term_ticket_generated) checkbox

I know how to set the Business Rule to run on the update of the State field in the "Desktop Services" table, but I am unsure how to write the Business Rules script that would then make these three updates to the corresponding User record.

Thanks

1 ACCEPTED SOLUTION

Here you go

 

var usr = new GlideRecord('sys_user');

 

usr.addQuery('sys_id',current.<user sys id>);// or get user sys_id from desktop service task table

 

usr.query();

 

while(usr.next()){

 

 

usr.u_term_date = usr.u_hire_date;

 

usr.active = "false";

 

usr.u_term_ticket_generated = "true";// provided this is Boolean column

 

usr.update();

 

}

 

Regards,

Sachin

View solution in original post

10 REPLIES 10

Can you please mark my answer as correct so that others can benefit?

 

Regards,

Sachin

jmiskey
Kilo Sage

I really do not want to accept that one because of the error in your code. As I mentioned in my previous post, if you re-post your solution with the correction to the typo so that your code is correct, I would be happy to accept that as the correct answer.

Please see corrected code below

 

var usr = new GlideRecord('sys_user');

 

usr.addQuery('sys_id',current.<user sys id>);// or get user sys_id from desktop service task table

 

usr.query();

 

while(usr.next()){

 

 

usr.u_term_date = user.u_hire_date;

 

usr.active = "false";

 

usr.u_term_ticket_generated = "true";// provided this is Boolean column

 

usr.update();

 

}

 

Regards,

Sachin

jmiskey
Kilo Sage

Still one typo.  Can you fix it?

usr.u_term_date = user.u_hire_date;

Here you go

 

var usr = new GlideRecord('sys_user');

 

usr.addQuery('sys_id',current.<user sys id>);// or get user sys_id from desktop service task table

 

usr.query();

 

while(usr.next()){

 

 

usr.u_term_date = usr.u_hire_date;

 

usr.active = "false";

 

usr.u_term_ticket_generated = "true";// provided this is Boolean column

 

usr.update();

 

}

 

Regards,

Sachin