setting the table field using record producer script

varal
Tera Contributor

I have created custom table in custom app. The table is extended from task table.field name: u_user_name

present on the task table from record producer created for the custom table. We want to set user name field using record producer script.

current.setValue('u_user_name',producer.customer);
 
varal_0-1794470461633.png

 

This is the field i added the screenshot i tried record producer script, before business rule , from fix script also i tried for testing purpose but unable to set the value.

varal_1-1794470663374.png

 

Could you please help me on above issue.
Thanks in advance!

4 REPLIES 4

Ankur Bawiskar
Tera Patron

@varal 

record producer is on which table?

is customer variable reference to user table?

Aditya_hublikar
Giga Sage

Hello @varal ,

 

As per your question you have to set user_name field on your custom table using record producer and your custom table extends the task table so that user_name field get inherited to your custom table  am i right ?

So you can directly set value of that user_name field like shown in image : 

Aditya_hublikar_1-1794473543075.png

 

customer variable is reference type and its reference table is sys_user  correct ? 

 

Try to set value using Background script :

var gr=new GlideRecord('customtableName')

if(gr.get('sysIdOfYourRecord')

{

gr.setValue('u_user_name','sysIdOfUser')

gr.update();

}

Also check the application scope while updating value .

 

If this helps you then mark it as helpful and accept as solution .

Regards,
Aditya

Tanushree Maiti
Tera Patron

Hi @varal 

 

Is your customer variable is Reference variable or single line text. 

 

Can you share your producer script screen shot.

 

yashkamde
Giga Sage

Hello @varal ,

 

Try using any one approach to resolve and properly set u_user_name

 

1) Instead of using current.setValue() in the Script section, let ServiceNow handle the mapping natively:

  • Look for the Field name (or Map to field) attribute and select u_user_name.

 

2) Using Script :

  • If u_user_name is a Ref Field, make sure your variable producer.customer is passing the sys_id

 

// Ensure you are assigning the sys_id properly
current.u_user_name = producer.customer; 
// OR using setValue
current.setValue('u_user_name', producer.customer);

 

  • If u_user_name is a String Field, so use .getDisplayValue() or convert it for storing:
current.u_user_name = producer.customer.getDisplayValue(); 
// or if producer.customer is a reference variable:
var grUser = new GlideRecord('sys_user');
if (grUser.get(producer.customer)) {
    current.u_user_name = grUser.getValue('name'); // or user_name
}

 

If my response helped mark as helpful and accept the solution.