Updating sys_user table using workflow

Ramel
Mega Guru

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

8 REPLIES 8

souren0071
Tera Expert

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


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();


                  }


        }


The code you have written should work properly for your requirement. Is not it working?



Regards,


Souren


The code I posted worked perfectly. Thanks for the help Souren and Pradeep