The CreatorCon Call for Content is officially open! Get started here.

Record Producer

vidhya_mouli
Giga Sage

I have a record procedure with some variables. I have added this record producer to my service portal using a widget. When i submit this form, all the fields gets updates as expected except for one field u_employee.

 

This is the  my script in the record producer:

 

/** This script is executed before the Record is generated
* `current`- GlideRecord produced by Record Producer
* Don't use `current.update()` or `current.insert()` as the record is generated by Record Producer
* Don't use `current.setValue('sys_class_name', 'xxx')` as this will trigger reparent flow and can cause data loss
* Avoid `current.setAbortAction()` and generate a separate record
* Use `producer.var1` to access variables
*/

var userID = gs.getUserID();
var employeeGR = new GlideRecord("u_employee_sv");
employeeGR.addQuery('u_reference_1',userID);
employeeGR.query();


if(employeeGR.next()){
	gs.addInfoMessage('INSIDE0: '+employeeGR.getDisplayValue('u_display_value'));
	gs.addInfoMessage('INSIDE1: '+employeeGR.getValue('u_display_value'));
	u_employee = employeeGR.getDisplayValue('u_display_value');

}

 

 

SN.png

u_employee is blank when I submit the form. What am I doing wrong?

1 ACCEPTED SOLUTION

I was able to solve this issue by using sysid instead of display value in the script. 

View solution in original post

9 REPLIES 9

Rahul RJ
Giga Sage

@vidhya_mouli you can try below code

current.u_employee=employeeGR.getDisplayValue('u_display_value');

 

Mark this as Helpful / Accept the Solution if this clears your issue.

Regards,

RJ

 

Adrian Ubeda
Mega Sage

Hi vidhya mouli, 

Use current.u_employee for assigning that value with the display value of the record retrieved from glideRecord, however getDisplayValue with argument I believe is recommended for widget scripting, instead of that try this code below:

/** This script is executed before the Record is generated
* `current`- GlideRecord produced by Record Producer
* Don't use `current.update()` or `current.insert()` as the record is generated by Record Producer
* Don't use `current.setValue('sys_class_name', 'xxx')` as this will trigger reparent flow and can cause data loss
* Avoid `current.setAbortAction()` and generate a separate record
* Use `producer.var1` to access variables
*/

var userID = gs.getUserID();
var employeeGR = new GlideRecord("u_employee_sv");
employeeGR.addQuery('u_reference_1',userID);
employeeGR.query();

if(employeeGR.next()){
	current.u_employee = employeeGR.getDisplayValue();
}
If it was helpful, please give positive feedback! ✔
☆ Community Rising Star 22, 23 & 24 ☆

When I use current.u_employee, i get this warning:

 

ErrorUnique Key violation detected by database ((conn=3328) Duplicate entry '9508509c1b3121105a7f6464604bcb6b' for key 'PRIMARY')

 

However u_employee is neither unique not primary.

 

 

Are you doing any update on any table? Is there any BR triggered in the same table where you are inserting record?

If it was helpful, please give positive feedback! ✔
☆ Community Rising Star 22, 23 & 24 ☆