Only Update records using Record producer

Sujitha2
Mega Guru

Hi,

I am trying to use record producer on sys_user table to update fields like email/dob etc. But the record producer that I have created is not updating properly. Instead its creating a new record. Used this 'current.setAbortAction(true)' but this is not working. Instead getting an error message ->  Error: Unique Key violation detected by database ((conn=11872) Duplicate entry '844b673e87d29d50fea1ebd73cbb35fe' for key 'user_name')

Can someone help me on this? Attaching below script which I used on Script section of Record producer.

 

var grUser = new GlideRecord('sys_user');
grUser.addEncodedQuery('sys_id=' + current.user_id);
grUser.query();
if(grUser.next()){
	grUser.email= producer.email;
        grUser.u_date_of_birth = producer.u_date_of_birth; 
	grUser.u_date_of_joining = producer.u_date_of_joining;
	grUser.update();
	gs.addInfoMessage('User record updated successfully');
        current.setAbortAction(true);
}

 

  Thanks in Advance

1 ACCEPTED SOLUTION

Sujitha2
Mega Guru

I found it myself, I made a mistake on the query. It is supposed to be producer.user_id and not current.user_id

var grUser = new GlideRecord('sys_user');
grUser.addEncodedQuery('sys_id=' + producer.user_id);
grUser.query();
if(grUser.next()){
	grUser.email= producer.email;
        grUser.u_date_of_birth = producer.u_date_of_birth; 
	grUser.u_date_of_joining = producer.u_date_of_joining;
	grUser.update();
	gs.addInfoMessage('User record updated successfully');
        current.setAbortAction(true);
}

 

View solution in original post

7 REPLIES 7

Correct, In User table it will start with u_, as it's a custom field.
Can you check in the record producer variable or variable set?
Regards,
Rahul

Sujitha2
Mega Guru

I found it myself, I made a mistake on the query. It is supposed to be producer.user_id and not current.user_id

var grUser = new GlideRecord('sys_user');
grUser.addEncodedQuery('sys_id=' + producer.user_id);
grUser.query();
if(grUser.next()){
	grUser.email= producer.email;
        grUser.u_date_of_birth = producer.u_date_of_birth; 
	grUser.u_date_of_joining = producer.u_date_of_joining;
	grUser.update();
	gs.addInfoMessage('User record updated successfully');
        current.setAbortAction(true);
}

 

I used similar kind of script but i am gatting erorr in the record producer after submission., please help in this

 

var usrGR = new GlideRecord('incident');
usrGR.addQuery('sys_id', producer.incident);
usrGR.query();
if (usrGR.next()) {
usrGR.short_description = producer.comment;
usrGR.update();
}
gs.info(producer.comment);
current.setAbortAction(true);

ArjunKumarLe1_0-1704947033693.pngArjunKumarLe1_1-1704947046642.png