How to determine if Lookup success or failed ?

评论

8 条评论

  • Avatar
    Shane Gilbert

    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.

    1
    评论操作 固定链接
  • Avatar
    Shahar Hayoun

    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?

    0
    评论操作 固定链接
  • Avatar
    Shane Gilbert

    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);
        }    
      });
    }
    1
    评论操作 固定链接
  • Avatar
    Shahar Hayoun

    So the if condition of the data.length can check if there was match or not?

    it keeps telling me 'A lookup is required'

    whether the number field match with the item from the sharepoint list and wether it isn't matched.

    only 'else' statement is executes in both cases.

     

    0
    评论操作 固定链接
  • Avatar
    Shane Gilbert

    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

     

    0
    评论操作 固定链接
  • Avatar
    Shane Gilbert

    If you are always getting to the else branch that means that result.isSuccess is always false. You should check the error logs for details on why it is failing.

    1
    评论操作 固定链接
  • Avatar
    Shahar Hayoun

    where can i see the error logs?

     

    0
    评论操作 固定链接
  • 0
    评论操作 固定链接

请先登录再写评论。