Getting error: Server JavaScript error Cannot read property "length" from undefined
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-21-2019 12:49 AM
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]);
}
})();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-21-2019 07:19 AM
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
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-03-2019 03:06 AM
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
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader