Getting error "The undefined value has no properties" when sending payload

chandan15
Tera Contributor

In picture 1, I have entered manual data which I am able to send through Spoke action.

But in Picture 2, I am creating payload by getting data from a customized table. I am getting Error "The undefined value has no properties". I have already checked all the script include installed by the Spoke. But couldn't found any script where this error code is mentioned. Can anyone is help me on this to identify what's wrong I am doing in this !!

5 REPLIES 5

Sukraj Raikhraj
Kilo Sage

Looks like one of the variable is not getting assigned a value.  hard to tell from the screenshot but I would start there as that what it looks like the error message is related to. 

all the value matched as per the upload Action Format, only date format is seems different, it this the only reason to be failure !

Sagar Agarwal
Mega Guru

Hi Chandan,

 

You are getting this error because you are trying to access a property of an object that doesn't exist.

 

 

I have explained this with an example script.

If you have a script then check if you are accessing your properties correctly

Also, Your object is a mix of objects and Array, check and see if you are parsing in the correct way.

Eg: 

 

// Scenario 1
var obj = {
	one: {
		display_value: "One",
		value: "one",
	},
	two: {
		display_value: "Two",
		value: "two",
	},
};

gs.log(obj.one.display_value);
// >> Output: One

// Scenario 2
var obj = {
};

gs.log(obj.one.display_value);
// >> Output: error > The undefined value has no properties

 

I have tried by changing output from array.object to object type, but it is not able to select in Upload action, however input for upload action is array.object type.

I have also tried by removing array type operator from the below script, still getting the same error

(function execute(inputs, outputs) {
    var reqJson = {};
    var tcq = inputs.tcq;
    var obj = {};
    var gr = tcq;
   
    while (gr.next()) {
        if (!obj[gr.user + '']) {
            obj[gr.user + ''] = {};
        }
        if (!obj[gr.user + ''][gr.week_starts_on + '']) {
            obj[gr.user + ''][gr.week_starts_on + ''] = {};
        }
        var arr = ['sunday',
            'monday',
            'tuesday',
            'wednesday',
            'thursday',
            'friday',
            'saturday'
        ];
        for (i = 0; i < arr.length; i++) {
            var temp = Number(obj[gr.user + ''][gr.week_starts_on + ''][arr[i]]);

            obj[gr.user + ''][gr.week_starts_on + ''][arr[i]] = temp ? temp + Number(gr[arr[i]]) : Number(gr[arr[i]]);
        }
        // 
    }

    //gs.print(JSON.stringify(obj));

    var data_array = [];
    for (var x in obj) {
        //gs.print(x + ": "+ obj[x])
        for (var y in obj[x]) {
            //gs.print(y + ": "+ obj[x][y]['monday'])

            var rolgr = new GlideRecord('u_fieldglass_time_card_rollup');
            rolgr.initialize();
            rolgr['u_week_start_date'] = y;
            rolgr['u_user'] = x;
            rolgr['u_sunday'] = obj[x][y]['sunday'];
            rolgr['u_monday'] = obj[x][y]['monday'];
            rolgr['u_tuesday'] = obj[x][y]['tuesday'];
            rolgr['u_wednesday'] = obj[x][y]['wednesday'];
            rolgr['u_thursday'] = obj[x][y]['thursday'];
            rolgr['u_friday'] = obj[x][y]['friday'];
            rolgr['u_saturday'] = obj[x][y]['saturday'];
            var sys_id = rolgr.insert();
            data_array.push(sys_id.toString());
        }


    }
    if (rolgr.length > 0) {
        throw new Error("Missing mandatory fields" + " " + rolgr);
    }
    var header = {
        "headers": {
            "Type": "Full_Time_Sheet_with_Revision_upload", 
            "Date Format": "MM/dd/yyyy",
            "Supplier Review": "True",
            "Comments": "True",
            "Send Notification?": "True",
            "Language": "English (United States)",
            "Transaction": "False",
            "Approval Required": "False", 
            "Submit": "True",
            "Associate Unassigned Cost Centers to Workers": "True"
        },
    };
    gs.log("SAP array" + data_array.toString());
    var optarr = [];
    var gr1 = new GlideRecord("u_fieldglass_time_card_rollup");
    gr1.addQuery("sys_id", "IN", data_array.toString());
    gr1.query();
    while (gr1.next()) {
        var obj1 = {};
        //obj1.user = gr1.u_user.getDisplayValue().toString();
        obj1.Cost_Center_Code = "0000" + gr1.u_user.cost_center.getDisplayValue().toString();
        obj1.Fri_Hrs = gr1.u_friday.toString();
        obj1.Mon_Hrs = gr1.u_monday.toString();
        obj1.Rate_Category_Code = 'ST';
        obj1.Sat_Hrs = gr1.u_saturday.toString();
        obj1.Sun_Hrs = gr1.u_sunday.toString();
        obj1.Task_Code = "Hours Worked";
        obj1.Thu_Hrs = gr1.u_thursday.toString();
        obj1.Tue_Hrs = gr1.u_tuesday.toString();
        obj1.UOM = "Hr";
        obj1.Wed_Hrs = gr1.u_wednesday.toString();
        obj1.Week_Start_Date = gr1.u_week_start_date.toString();
        obj1.Worker_ID = gr1.u_user.u_worker_id.toString();
        obj1.Date = gr1.u_week_start_date.toString();

        optarr.push(obj1);
    }

    gs.log("SAP__" + optarr.length);
    gs.log("SAP__" + JSON.stringify(optarr));
    gs.log("SAP__" + (optarr.toString()));
    
    var optc = JSON.stringify(optarr);
    outputs.optc = optc;

})(inputs, outputs);