How to determine if Lookup success or failed ?
Hey, i'm trying to execute function that determines if lookup has succeed or failed and want to make condition if it success.
function testa()
{
var options = {};
options.lookupName = 'idLookup';
eFormHelper.executeLookup(options, function (result)
{
if (result.isSuccess)
{
console.log("nono"); //logs the data which holds the lookup result
}
else
{
console.log("hara"); // logs the hold exception object
}
});
}
this is what i've tried but it keeps logs "hara" even when the lookup succeed.
-
Code looks right. Have you tried debugging the code? You can add the line
debugger;
right before your check on result.isSuccess and with the Developer Tools open in your browser you will be able to inspect all of the values and step through the code. Also you can look in the error logs for detailed error messages.
-
Yeah but in the debugging process nothing happens other than “hara” and undefined after that.
Maybe im trying to do something else?
Eventually i want to check if an item exists in SharePoint List. There is number field to enter and than it executes Lookup. So i want to check if the number(item) exists in the SharePoint List hence if the Lookup Succeed to match. I’m doing something wrong? -
Not sure if I completely understand but you can check the data length to determine whether or not there were any matches to your lookup. Here is an example function that I use to lookup a department code. It will always be successful even when there are no matches, so I check the data length.
function lookupDepartment() {
var options = {};
options.lookupName = 'DepartmentLookup';
options.lookupType = eFormHelper.constants.lookuptype.namevalue;
eFormHelper.executeLookup(options, function (result) {
if (result.isSuccess) {
console.log(result.data);
if (result.data.length) { $('#DepartmentCode').val(result.data[0].Name); }
} else {
console.log(result.error);
}
});
} -
Yes, if there is a match then the length will be greater than 0. In JavaScript 0 is the same as false and 1 or greater is true. Here is a reference: https://developer.mozilla.org/en-US/docs/Glossary/Truthy
-
Look at this documentation:
https://helpdesk.agilepoint.com/hc/en-us/articles/360015474293-log-files
Please sign in to leave a comment.
Comments
8 comments