setting the table field using record producer script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 hours ago
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.
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 hours ago
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 hours ago
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 :
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 hours ago
Hi @varal
Is your customer variable is Reference variable or single line text.
Can you share your producer script screen shot.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 hours ago
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.