The CreatorCon Call for Content is officially open! Get started here.

Create a record in a table with data from the MRVS variable set

jkelvynsant
Tera Contributor

Hello community, I have an MRVS in a record producer and I need the values ​​passed to the MRVS to create a record in a table (x_acel2_csc_payment_extension_assistant). I created a BR for this, but for some reason it is not working. I need each row in the MRV to be a record in the table.

(function executeRule(current, previous /*null when async*/) {

    //MRVS
    var mrvs = current.variables.nota_fiscal;

    if (!mrvs) {
        return;
    }

    var rowCount = mrvs.getRowCount();

    if (rowCount == 0)
        return;

    for (var i = 0; i < rowCount; i++) {
        var row = mrvs.getRow(i);

        var gr = new GlideRecord('x_acel2_csc_payment_extension_assistant');
        gr.initialize();

        gr.u_request_number = current.number;
        gr.u_invoice_number = row.invoice_number;
        gr.u_original_expiration_date = row.original_due_date_;
        gr.u_days_to_extend = row.days_to_extend;
        gr.u_new_date = row.new_date;
        gr.u_value = row.value;

        var newSysId = gr.insert();
    }


})(current, previous);

  

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@jkelvynsant 

try this

-> Business rule should be after insert

-> variable set name should be correct and variable names should be correct

(function executeRule(current, previous /*null when async*/ ) {

    //MRVS
    var mrvs = current.variables.nota_fiscal;
    if (!mrvs) {
        return;
    }
    var parsedData = JSON.parse(mrvs);

    if (parsedData.length == 0)
        return;

    for (var i = 0; i < parsedData.length; i++) {
        var row = parsedData[i];
        var gr = new GlideRecord('x_acel2_csc_payment_extension_assistant');
        gr.initialize();
        gr.u_request_number = current.number;
        gr.u_invoice_number = row.invoice_number;
        gr.u_original_expiration_date = row.original_due_date_;
        gr.u_days_to_extend = row.days_to_extend;
        gr.u_new_date = row.new_date;
        gr.u_value = row.value;
        var newSysId = gr.insert();
    }

})(current, previous);

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

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

View solution in original post

1 REPLY 1

Ankur Bawiskar
Tera Patron
Tera Patron

@jkelvynsant 

try this

-> Business rule should be after insert

-> variable set name should be correct and variable names should be correct

(function executeRule(current, previous /*null when async*/ ) {

    //MRVS
    var mrvs = current.variables.nota_fiscal;
    if (!mrvs) {
        return;
    }
    var parsedData = JSON.parse(mrvs);

    if (parsedData.length == 0)
        return;

    for (var i = 0; i < parsedData.length; i++) {
        var row = parsedData[i];
        var gr = new GlideRecord('x_acel2_csc_payment_extension_assistant');
        gr.initialize();
        gr.u_request_number = current.number;
        gr.u_invoice_number = row.invoice_number;
        gr.u_original_expiration_date = row.original_due_date_;
        gr.u_days_to_extend = row.days_to_extend;
        gr.u_new_date = row.new_date;
        gr.u_value = row.value;
        var newSysId = gr.insert();
    }

})(current, previous);

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

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