Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Getting Values from Multi Row Variable Set Record Producer

gregrice
Tera Expert

I am having trouble inserting data into my related list from a MRVS for my record producer. Any suggestions on what I am doing wrong?

MRVS name = 'other contacts';

variable name = 'name';

 

var contactArr = producer.other_contacts;
var contactCnt = producer.other_contacts.getRowCount();

if (contactCnt > 0) {
    for (i = 0; 1 < contactCnt; i++) {
    var gr = new('related_record');
    gr.initialize();
   gr.setValue('name',contactArr[i].name);
   database.insert();
 }
}

I am getting the correct row count I just cannot get the data from the array;

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

the value you get from MRVS is json; you need to parse that

also print if you are getting proper json

correct this mistake/error; i < contactCnt

for (i = 0; i < contactCnt; i++) {

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

3 REPLIES 3

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

the value you get from MRVS is json; you need to parse that

also print if you are getting proper json

correct this mistake/error; i < contactCnt

for (i = 0; i < contactCnt; i++) {

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

gregrice
Tera Expert

Thanks Ankur, I am pretty close. I added a string variable to my MRVS to test

MRVS = Other Contacts

variables = Name (reference to sys_id)

                 test (string variable)

var contactArr = JSON.parse(producer.other_contacts);

var contactCnt = producer.other_contacts.getRowCount();

if (contactCnt > 0) {
    for (i = 0; i < contactCnt; i++) {
    var gr = new('related_record');
    gr.initialize();

    gr.setValue('test',contactArr[i].test); <--------- this works
   gr.setValue('name',contactArr[i].name);  <------- this doesn't name is a reference variable?
   database.insert();
 }
}

It's working now. I deleted my variable and re-added not sure what the issue was.