Error coming as cannot convert null to object for a mrvs in flow designer

shalikasurbhi1
Tera Contributor

I have a multi row variable set which has some variables. Here for one of the variables the user is not entering any value. And the error is coming as  cannot convert null to object

(function execute(inputs, outputs) {
var inp = JSON.parse(JSON.stringify(inputs.resource_list));
var mvrs =JSON.stringify(inp);
var rowCount = inp.length;
    for (var i = 0; i < rowCount; i++) {
        var row = inp[i];
        gs.log("mvrs 3"+JSON.stringify(row));
        var resource_no = row.resource_no;
        var count = row.count;
        var resource_target_platform = row.resource_target_platform;
        var resource_location_mrvs = row.resource_location_mrvs;
        var resource_type = row.resource_type;
        var resource_subtype = row.resource_subtype;
        var resource_sku = row.resource_sku;
        var price_month = row.price_month;
        var cost = row.cost;
        var advance_attribute_sample_json = row.advance_attribute_sample_json;   
    }
})(inputs, outputs);
The error is coming as
shalikasurbhi1_0-1721653613102.png

I also tried to add code as
if(advance_attribute_sample_json ==null)

advance_attribute_sample_json == "  ";

Still the same error was coming. 

1 ACCEPTED SOLUTION

Satishkumar B
Giga Sage
Giga Sage

Hi @shalikasurbhi1 

check the below code:

 

 

(function execute(inputs, outputs) {
    // Parse the resource_list from inputs
    var inp = JSON.parse(JSON.stringify(inputs.resource_list));
    var mvrs = JSON.stringify(inp);
    var rowCount = inp.length;

    // Iterate through each row
    for (var i = 0; i < rowCount; i++) {
        var row = inp[i];
        gs.log("mvrs 3" + JSON.stringify(row));

        // Assign default values if the variable is null or undefined
        var resource_no = row.resource_no || '';
        var count = row.count || 0;
        var resource_target_platform = row.resource_target_platform || '';
        var resource_location_mrvs = row.resource_location_mrvs || '';
        var resource_type = row.resource_type || '';
        var resource_subtype = row.resource_subtype || '';
        var resource_sku = row.resource_sku || '';
        var price_month = row.price_month || 0;
        var cost = row.cost || 0;
        var advance_attribute_sample_json = row.advance_attribute_sample_json || {};

        // Proceed with your logic using these variables
    }
})(inputs, outputs);

 

 

 

……………………………………………………………………………………………………

Please Mark it helpful 👍and Accept Solution✔️!! If this helps you to understand. 

View solution in original post

4 REPLIES 4

Satishkumar B
Giga Sage
Giga Sage

Hi @shalikasurbhi1 

check the below code:

 

 

(function execute(inputs, outputs) {
    // Parse the resource_list from inputs
    var inp = JSON.parse(JSON.stringify(inputs.resource_list));
    var mvrs = JSON.stringify(inp);
    var rowCount = inp.length;

    // Iterate through each row
    for (var i = 0; i < rowCount; i++) {
        var row = inp[i];
        gs.log("mvrs 3" + JSON.stringify(row));

        // Assign default values if the variable is null or undefined
        var resource_no = row.resource_no || '';
        var count = row.count || 0;
        var resource_target_platform = row.resource_target_platform || '';
        var resource_location_mrvs = row.resource_location_mrvs || '';
        var resource_type = row.resource_type || '';
        var resource_subtype = row.resource_subtype || '';
        var resource_sku = row.resource_sku || '';
        var price_month = row.price_month || 0;
        var cost = row.cost || 0;
        var advance_attribute_sample_json = row.advance_attribute_sample_json || {};

        // Proceed with your logic using these variables
    }
})(inputs, outputs);

 

 

 

……………………………………………………………………………………………………

Please Mark it helpful 👍and Accept Solution✔️!! If this helps you to understand. 

Still the same error is coming

Also when i raised another request where I filled all the variables still the same error was coming

-O-
Kilo Patron
Kilo Patron

resource_list seems to be a string so

var inp = JSON.parse(JSON.stringify(inputs.resource_list));

should really be:

var inp = JSON.parse(inputs.resource_list);

 

As a side note, variable mvrs is not used, so

var mvrs =JSON.stringify(inp);

should be removed.