Getting error: Server JavaScript error Cannot read property "length" from undefined

Shusovit
Mega Expert

Hi can someone help me with the error and what's wrong with the below code line.

 

(function () {
if (input) {
data.sys_id = input.sys_id;
data.table = input.table;
}
else {
data.sys_id = options.sys_id || $sp.getParameter("sys_id");
data.table = options.table || $sp.getParameter("table");
}

data.sysUserID = gs.getUser().getID();

var taskGR = new GlideRecord(data.table);

data.taskModelList = [];
if (taskGR.get(data.sys_id)) {

data.name = taskGR.getDisplayValue();
var loggedInSysUserID = gs.getUser().getID();

data.isLoggedInUsersProfile = true;

var taskForm = $sp.getForm(data.table, data.sys_id);

data.taskView = taskForm._view;
data.taskModel = taskForm._fields;

for (var i = 0; i < data.taskView.length; i++)  //ITS POINTING TO THIS LINE OF CODE
data.taskModelList.push(data.taskModel[data.taskView[i].name]);
}

})();

2 REPLIES 2

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

That could be because the data.taskView might be empty and if you try to use length property on empty that error comes

try to alert that and check if that is empty or not?

Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.
Thanks
Ankur

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

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

Any update on this?
Can you mark my answer as correct, helpful if you were able to achieve the requirement. This helps in removing this question from unanswered list and helps users to learn from your thread. Thanks in advance.

Regards
Ankur

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