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

nazhath
Kilo Explorer

Hi

 

I am still unable to implement your code

i am trying to update a custom built table when a new record is inserted in the user table based if the id's match (not sys_id).

 

Thanks