Record Producer mapping to Related list fields

Shubha2
Mega Guru

Hi Everyone

I need to map 'Requested by' and 'Requested for' fields from the Input form and map it to fields in the Related list table.

I used a small script, in the scripting section of the producer, 'Requested by' from the form should map it to reporting party field in the related list. 

var grReportingParty = new GlideRecord('related_list_table');
grReportingParty.initialize();

grReportingParty.setValue('parent_case', current.sys_id);
grReportingParty.setValue('role', 'Reporting Party');
grReportingParty.setValue('type', 'Employee');
grReportingParty.insert();

 

  1.  Any help would be appreciated Not too sure how to use this

producer.Requested_by = ReportingParty;

2. Second question - I have created many variables and have mapped it to fields on the parent case. But I also used the Script section of the record producer to make all the questions available in the notes section. Will there be a conflict if we use both? because, when I used only variables to map, it was working but now it is not quite working.

var notes = producer.first_varblename;
notes += "\n"+producer.secondvariblename;
notes += "\n"+producer.thirdvariablename;
current.description = notes;

Could you please help me with this? Your help is greatly appreciated.

Thank you
Shubha

 

1 ACCEPTED SOLUTION

I'm not sure what tables you are working with.... but I'm pretty sure there is a Business Rule on one of the tables you are inserting the record into. That business rule is most likely causing the extra case to be created.

You will need to identify the Business Rule(s) that are causing this to happen and see if you can work around them somehow. (i.e. do not trigger them). 

If you using a GlideRecoord you can consider using .setWorkflow(false) which prevents the business rule from running. 

 

View solution in original post

14 REPLIES 14

 

  • Use current.*FIELD_NAME* to reference fields on the record being created.
  • Use producer.*VARIABLE_NAME* to reference values entered by the end user.
var grReportingParty = new GlideRecord('related_list_table');
grReportingParty.initialize();

grReportingParty.setValue('parent_case', current.sys_id);
grReportingParty.setValue('role', 'Reporting Party');
grReportingParty.setValue('type', 'Employee');
grReportingParty.setValue('ReportingParty​ field', producer.Requested_by);//use any field here

grReportingParty.insert();

var notes ="first_varblename: "+ producer.first_varblename+"\nsecondvariblename: "+producer.secondvariblename+"\nthirdvariablename: "+producer.thirdvariablename+ "\nthirdvariablename: "+producer.thirdvariablename;

current.description = notes;

Thank you so much for your replies. Really appreciated your time. This was really helpful.

 

Chris McDevitt
ServiceNow Employee
ServiceNow Employee

Hi,

When thinking about a Record Producer AND in your case, a Related List you need to think about three separate things.

1. The variables on the RECORD PRODUCER itself (producer.varable_name).

2. The fields on the TARGET/TABLE of the Record Producer (current.field_name).

3. The fields on the RELATED LIST (Which is really another TABLE). (<gliderecord>.field_name).

After evoking a Record Producer you have access to:

- "producer"

- "current"

What you do not have access to is the related list, which is just a GlideQuery away (to that table).

First, you will need to understand the underlying relationship between the TARGET RECORD and RELATED LIST RECORD (RLR). (There are few different ways)

You will then need to craft a GlideQuery to access(Create or Update) the RLR. Here is an example to create a new record:

var gr = new GlideRecord('RLR_TABLE');
gr.initialize(); 
gr.name = producer.varable_name; //Like this 
gr.setValue('description', producer.description); //Or my prefered
gr.insert();

Or you can update an existing record.

 

 

Thank you so much for taking time to help me with this. This is very helpful and I understand RP and RLR much better. Wish the documentation was this clear. I changed my script and now it is working. I was able to create a record in the related list and looks wonderful!! I am so happy now!! Thanks a lot!!

Hi,

Glad you got a better understanding?

To be clear, the "documentation" is clear...what was explained is basic fundamentals of tables and their relationship. Once you understand that, you can work from that. Within your own post you already utilized or mentioned...GlideRecord to initialize a new record and insert it...and within the 2nd part of your post, you had stated you used: producer.first_variable_name, etc. for other things.

So it's unclear how in the first part of your question where you used a gliderecord to create a new record elsewhere and not use "producer.variable"...but then in the second part of your post, you did. Again, all pointing to just understanding the basic fundamentals.

Best of luck to you!

 


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!