How do I automatically update the selection of a choice field when another choice field from another table changes?

dmixer
Mega Contributor

Okay... to break down my question.

I am working with two tables, sys_user and the cmdb.

Basically, every user record in the sys_user table is assigned equipment that is stored in the cmdb table.

When a user leaves the company, their status (choice field) in sys_user changes from "Active" to "Termed"

Upon this status being changed from "Active" to "Termed", I need to change another choice field (on the users CI record) in the cmdb from "Active" to "Recover", so our team knows we need to get their equipment.

Example: John Doe is an Active Employee with Active equipment (iPad tablet) assigned to him. 3 months later, John quits so his record in the sys_user table changes from Active to Termed (via scheduled import) now his equipment status needs to change from Active to Recover - so my team knows they need to recover Johns hardware.

Whats in bold is my problem and I am looking for a way to automate these status changes. I am looking for an "out of the box" method of doing this since I have very little knowledge of javascript.

Would anyone be kind enough to point me to the right direction?

1 ACCEPTED SOLUTION

Hi Daniel,



Make sure that the field column name and the values are set properly in the script.


View solution in original post

12 REPLIES 12

Hi Daniel,



Make sure that the field column name and the values are set properly in the script.


ok if it isn't updating the records... we have a couple of possibilities... either the br isn't being triggered or the querry is off...



so do some loggign or add info messages... first one would be the first step in the br... log or add an addinfo message that you are in the br.. this lets you know your condition is working right <if not verify the active flag is being set correctly on the user record>



assuming that one works.. then your next test would be to test your queries..



inside of the while loop i would throw a log message of "Found asset for " + current.user_name + " asset is " + assignedAssets.name);



then disable one and check your logs to see what you get... i suspect strongly that since you are setting the active status to Termed we may have a problem with the initial condition for the BR


dmixer
Mega Contributor

Just FYI to anyone who stumbles upon this post... thank you everyone for your help!



This was the final script that did the job:



    var assignedAssets = new GlideRecord("cmdb_ci");


  gs.addInfoMessage('in loop');


  assignedAssets.addQuery("assigned_to", current.sys_id);


  assignedAssets.query();



  while(assignedAssets.next()) {


  assignedAssets.install_status = 128;


  assignedAssets.update();


  }


}