Hey guys I need a little help from some scripting pros.
function getuser(pincode) {
var getusers = web.PostData('https://api.7shifts.com/v1/'+method2+'/','',''+apikey+'','');
var user = JSON.parse(getusers);
for(var i=0; i<user.data.length; i++){
if(user.data[i].user.employee_id == pincode)
return user.data[i].user.id;
}
}
This function is valid… the problem is the data is so huge if it tries to search for something that is way way way down near end it returns undefined. Im guessing its timing out?
Any ideas on how to improve this?
In this case the restaurant has a LOT of employees if I search for an employee that is near end of the list it returns undefined… if I search for one near the start it works fine.
function getuser(pincode) {
var getusers = web.PostData('https://api.7shifts.com/v1/'+method2+'/','',''+apikey+'','');
var userList = JSON.parse(getusers);
for (var i = userList.data.length; i > -1; i--) {
if (userList.data[i].user.employee_id == pincode) return userList.data[i].user.id;
}
}
You should also verify if the response is correctly formated (http://jsonviewer.stack.hu/) any error in the json would make to fail the script, since samba scripting engine cannot throw any exception its harder to guess whats happening, have you tried to run that code in javascript to see if is samba problem? I don’t think 500 entries are too large to fail.