- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-16-2020 09:54 PM
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;
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-16-2020 10:21 PM
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
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-16-2020 10:21 PM
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
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-17-2020 08:17 AM
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();
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-17-2020 08:48 AM
It's working now. I deleted my variable and re-added not sure what the issue was.