MRVS Issue from record producer to Custom table via related list to store the submitted date from th

JyothiD
Tera Contributor

I Want to populate my mrvs data from record producer to a table under a related list of a custom table form view.

I have created a custom table for the other fields to store the record producer data once submitted. And I have created child table with year, month, no_of_seats_require as same as MRVS fields, and parent field which is reference to custom table.

In the producer side I have used this code to initialize the record on the table mentioned:

(function executeProducerScript(current, producer) {
    // Insert parent record first
    current.insert();

    // Get MRVS JSON (internal name = monthly_seat_demand)
    var raw = producer.monthly_seat_demand;
    if (!raw) return;

    var rows = JSON.parse(raw);  // Array of objects
    var gr = new GlideRecord('x_ggisu_seat_deman_seat_demand_mrvs');

    for (var i = 0; i < rows.length; i++) {
        var r = rows[i];

        gr.initialize();
        gr.parent = current.sys_id; // link back to Seat Request Form
        gr.year = r.year || '';
        gr.month = r.month || '';
        gr.no_of_seats_require = parseInt(r.no_of_seats_require, 10) || 0;
        gr.insert();
    }

})(current, producer);

this is not working and rows are not inserted in related list of custom table. How I can achieve this. Please provide the resolution.
1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@JyothiD 

record producer is on which target table? Parent table?

If yes then why to write current.insert() when record will already be created when you submit record producer?

what debugging did you do in your script?

1) table name and parent field is correct?
2) fields you are trying to set are correct? is the field type matching against variable type?

3) variable names from MRVS are correct?

4) add gs.info() and see

If you are trying to set reference field from choice variable then it won't work

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

View solution in original post

9 REPLIES 9

JyothiD
Tera Contributor

Record producer is on Parent table - x_ggisu_seat_deman_seat_request_form
Child table - x_ggisu_seat_deman_seat_demand_mrvs

JyothiD_2-1757409380924.png

 

 

Ankur Bawiskar
Tera Patron
Tera Patron

@JyothiD 

record producer is on which target table? Parent table?

If yes then why to write current.insert() when record will already be created when you submit record producer?

what debugging did you do in your script?

1) table name and parent field is correct?
2) fields you are trying to set are correct? is the field type matching against variable type?

3) variable names from MRVS are correct?

4) add gs.info() and see

If you are trying to set reference field from choice variable then it won't work

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

Record producer is on Parent table  x_ggisu_seat_deman_seat_request_form
Child table  x_ggisu_seat_deman_seat_demand_mrvs

 

logs are coming, but data is not storing in parent table under related list

@JyothiD I didn't see anything in Accepted solution given.. so I guess you are not interested in our Answer .!!
Anyway all the best

--------------------------------------------------------------------------------------------------------------------------


If you found my response helpful, I would greatly appreciate it if you could mark it as "Accepted Solution" and "Helpful."
Your support not only benefits the community but also encourages me to continue assisting. Thank you so much!

Thanks and Regards
Ravi Gaurav | ServiceNow MVP 2025,2024 | ServiceNow Practice Lead | Solution Architect
CGI
M.Tech in Data Science & AI

 YouTube: https://www.youtube.com/@learnservicenowwithravi
 LinkedIn: https://www.linkedin.com/in/ravi-gaurav-a67542aa/

@JyothiD 

unless you add logs you won't know what came and how are you mapping.

try this

(function executeProducerScript(current, producer) {

    // Get MRVS JSON (internal name = monthly_seat_demand)
    var raw = producer.monthly_seat_demand.toString();
    if (!raw) return;

    var rows = JSON.parse(raw); // Array of objects

    for (var i = 0; i < rows.length; i++) {
        var r = rows[i];

        var gr = new GlideRecord('x_ggisu_seat_deman_seat_demand_mrvs');
        gr.initialize();
        gr.parent = current.sys_id; // reference field to parent
        gr.u_year = r.year || ''; // use internal column names from MRVS
        gr.u_month = r.month || '';
        gr.seat_request = parseInt(r.no_of_seats_require, 10) || 0;
        gr.insert();
    }

})(current, producer);

If my response helped please mark it correct and close the thread so that it benefits future readers.

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