Update user record from workflow?

Sandy7
Tera Expert

Hello everyone,

I have a catalog item with a workflow attached. 

After one of the tasks is closed in the workflow, I need to update the sys_user table (user record). There is a checkbox field called "sensitive_employee" that I want to be checked. 

So on the catalog item form, there is a "Requested For" variable, and the user record for that person is where this update needs to happen. 

So far I have a run script activity in the workflow that looks like this, but now luck. Any ideas? thanks!

var gr =new gliderecord("sys_user");
var ga = "u_sensitive_employee";
ga.setValue("u_sensitive_employee", 'true');
gr.update();

 

5 REPLIES 5

Zach Koch
Giga Sage

You almost have it, I corrected the script below.  You may need to adjust the field names to match, I was yours

var userVar = current.variables.requested_for
var userUpdate = new GlideRecord("sys_user");
userUpdate.addQuery('sys_id', userVar)
userUpdate.query()
if(userUpdate.next()){
userUpdate.u_sensitive_employee = true
userUpdate.update();
}

If this solved your issue, please mark this correct and helpful, thanks!

chrisperry
Giga Sage

Hi there,

Try updating your script as below:

var userGr = new GlideRecord("sys_user");
if (userGr.get(current.variables.requested_for.toString())) {
       userGr.setValue("u_sensitive_employee", true);
       userGr.update();
}

If this answer is helpful please mark correct and helpful!

Regards,

Christopher Perry

Thank you! This works perfectly 🙂 

Glad to hear it 🙂

Please mark my answer as correct and helpful to close this thread.

If this answer is helpful please mark correct and helpful!

Regards,

Christopher Perry