Access record producer multi-row variable set values from business rule in a scoped app

cloudyrobert
Kilo Guru

I'm hoping that I'm doing something stupid here... I'm trying to take values from a multi-row variable set on a record producer and create them as records in a table related to the one for which the primary record from the record producer is created. E.g. Record producer creates main record. Each row in the multi-row variable set is represented as a row in the supporting table, referencing the main record. This is all within a scoped app.

I've got it working with no issue from a background script once the record has been submitted. However, the same code (modified for context) doesn't work in a business rule running after insert on the table represented below as "x_payment."

/* used in background script only */
var current = new GlideRecord('x_payment');
current.get('__sys_id__');
/* */

var grRow = new GlideRecord('x_funding_sources');

var mrvs;
mrvs = current.variables.funding_sources;
var mrvsArray = JSON.parse(mrvs);

for (i = 0; i < mrvsArray.length; i++) {
    grRow.initialize();
    grRow.payment = current.sys_id;

    grRow.cost_center = mrvsArray[i].cost_center;
    /* etc. */
    grRow.insert();
}
1 ACCEPTED SOLUTION

mattgerry_TP13
Kilo Expert

Hey Robert-

I couldn't get this working with an After business rule either so I ran the business rule Async instead and that seemed to work well for me. Hope this helps!

View solution in original post

5 REPLIES 5

I am also having similar trouble. can you please share the script or BR