Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

I am getting this error message "org.mozilla.javascript.NativeArray@b7f7da"

PujaKar
Tera Contributor

I have a requirement where I need to update two field value through JSON via using "Product Config", but I am getting error on this.  

In Generic API Staging Table I received this "org.mozilla.javascript.NativeArray@b7f7da" in value.

below is the "Product config script" where I set the field and value.

key is setting but value is coming with this error.

 

 

 

(function getSys(objParam) {
    var JSONadrs;

    var grInStagng = new GlideRecord('abc_xyz');
    grInStagng.addQuery('sys_id', objParam.source_sysId);
    grInStagng.query();
    if (grInStagng.next()) {
        JSONadrs = grInStagng.payload;
        var parser = new global.JSONParser();
        var parsed = parser.parse(JSONadrs);
        var len = parsed.input.length;
        for (var i = 0; i < len; i++) {
            var fld1 = 'u_field_label' + [i];
            var fld2 = 'u_field_value' + [i];
            var fldKey = grInStagng.getValue(fld1, parsed.input[i].key);
            var fldVal = grInStagng.getValue(fld2, parsed.input[i].value);
            if (fldKey == 'code') {
                gs.info('checking field key' + fldKey);
                gs.info('checking field value' + fldVal[0]);
                if (fldVal == null || fldVal == "") {
                    return "";
                } else {
                   
                    gs.info('code' + fldVal);

                    return dateValue;
                }
            }
        }
    }
})(objParam);

 

 

 

JSON:

JSON is working fine as well.

 

 

 

{
    "DomainId": "A",
    "u_process_type": "B",
    "u_external_system": "C",
    "u_operation": "update",
    "ActivitySource": null,
    "ActivityId": null,
    "ActivityStatus": null,
    "CaseId": "abc123456790123456789012345",
    "input": [
        {
            "key": "states",
            "value": "Captured"
        },
         {
            "key": "code",
            "value": [
                {
                    "label": "ABC",
                    "value": "DEF"
                },
                {
                    "lable": "GHI,
                    "value": "JKL"
                }
            ]
        }

       
    ]
}

 

 

 

Please anyone help to resolved this issue.

 

 

 
2 REPLIES 2

Not applicable

Hello @PujaKar ,

 

Try below code to parse the JSON

 

JSON.parse(user_payload)

 

Thanks

Anand

 

I have tried but did not worked.

I have added this "JSON.parse(user_payload)" in the last else loop.

 

 

(function getSys(objParam) {
    var JSONadrs;

    var grInStagng = new GlideRecord('ABC_XYZ');
    grInStagng.addQuery('sys_id', objParam.source_sysId);
    grInStagng.query();
    if (grInStagng.next()) {
        JSONadrs = grInStagng.payload;
        var parser = new global.JSONParser();
        var parsed = parser.parse(JSONadrs);
        var len = parsed.input.length;
        for (var i = 0; i < len; i++) {
            var fld1 = 'u_field_label' + [i];
            var fld2 = 'u_field_value' + [i];
            var fldKey = grInStagng.getValue(fld1, parsed.input[i].key);
            var fldVal = grInStagng.getValue(fld2, parsed.input[i].value);
			
            if (fldKey == 'data') {
				//var obj = JSON.parse(fldVal);
                gs.info('checking field key' + fldKey);
                gs.info('checking field value' + JSON.parse(fldVal[0]));
                if (fldVal == null || fldVal == "") {
                    return "";
                } else {
    
					JSON.parse(fldVal.payload);
                    gs.info('data' + fldVal);

                    return dateValue;
                }
            }
        }
    }
})(objParam);