Updating sys_user table using workflow
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-01-2017 10:00 PM
Hi All,
Good day! I am trying to update the sys_user table fields with the value entered from the last completed task. I added a runscript in my workflow that includes the script to update the sys_user table based from the entered value in the task that was previously closed. However, what's happening is it is creating a new record in the sys_user table instead of updating the existing record.
Here's my script:
var gr = new GlideRecord("sn_hr_core_task");
gr.get(workflow.scratchpad.task1); //this is the task where I am getting the value of the 2 fields that I need to update in the sys_user table
gr.query();
if (gr.next()) {
var user = new GlideRecord("sys_user");
user.initialize();
user.u_gpid = gr.u_gpid;
user.email = gr.u_email_address;
user.update();
}
I am using user.update() but still inserting a new record. Any advice what am I I doing incorrectly?
Thanks in advance.
Ramel
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-02-2017 01:56 AM
Hi Ramel,
You want to update u_gpid, email field of user record from the task fields u_gpid, u_email_address. Now please let me know which user you want to update, is it present in the task itself?
Regards,
Souren
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-02-2017 02:42 AM
Hi Souren,
The user is not present in the task itself, only the employee ID of the user is the one I use to query.
var gr = new GlideRecord("sn_hr_core_task");
gr.get(workflow.scratchpad.task1);
gr.query();
if (gr.next()) {
var user = new GlideRecord("sys_user");
user.addQuery("employee_number", gr.u_employee_id);
user.query();
if(user.next()){
user.u_gpid = gr.u_gpid;
//workflow.info(gr.u_gpid);
user.email = gr.u_email_address;
user.update();
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-02-2017 04:03 AM
The code you have written should work properly for your requirement. Is not it working?
Regards,
Souren
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-03-2017 02:55 AM
The code I posted worked perfectly. Thanks for the help Souren and Pradeep