vLookup Custom Function

Home Forums Classic DFFS vLookup Custom Function

Viewing 3 reply threads
  • Author
    Posts
    • #18651
      Cameron
      Participant

        I’m trying to use a Custom Function in vLookup to show an * when certain conditions are true. I’m having trouble using item.get_item(‘Field’); when using a Lookup field – is this supported? It works fine when I try to grab the ID or Title but not the Lookup Field I want.

        Any other suggestions on how I can achieve this based on whether a Lookup field is setup?

        
        
        function isUnconfirmed(arg,item) {
            //if Job is empty return nothing
            if(!(item.get_item("Job"))){
                //If not a Job, check if argument is a valid date
                var parsedDate = Date.parse(arg);
        
                if (isNaN(arg) && !isNaN(parsedDate)) {
                    // Date found, return *
                    return "*";
                } else {
                    return "";
                }
            } else {
                return "";
            }
        }
      • #18693
        Alexander Bautz
        Keymaster

          Sorry for the delay – is your lookup field named “Job”? – if so, try using

          item.get_item("Job").get_lookupValue();

          or

          item.get_item("Job").get_lookupId();

          Alexander

        • #18695
          Cameron
          Participant

            Thanks Alexander,

            That’s correct, Job is the name of my Lookup field.

            Unfortunately I haven’t been able to get this to work. I noticed that Title and ID would return from the item object so I’ve got it working with the code below… but it’s slow.

            Basically I pass the ID and Field I want to check to another function which uses spjs_QueryItems to check if the field is set.

            
            
            function isUnconfirmed(arg,item) {
                //if a job return blank
                if(!(lookupValid("Job",item.get_item("ID")))){
                    //Not a Job, check if Quote accepted
                    var parsedDate = Date.parse(arg);
                    
                    // You want to check again for !isNaN(parsedDate) here because Dates can be converted
                    // to numbers, but a failed Date parse will not.
                    if (isNaN(arg) && !isNaN(parsedDate)) {
                        //Valid Accepted Date found, return nothing
                        return "";
                    } else {
                        return "*";
                    }
                } else {
                    //Item has a Job set, return nothing
                    return "";
                }
            }
            
            function lookupValid(strField,intID){
                //Function looks up the field for the supplied ID and returns true is a valid value is found
                if(isNaN(intID)||intID<1){
                    console.log("Invalid ID supplied");
                    return false;
                }
                qb = [];
                qb.push("<Where>");
                qb.push("<Eq>");
                qb.push("<FieldRef Name='ID' /><Value Type='Text'>"+intID+"</Value>");
                qb.push("</Eq>");
                qb.push("</Where>");
                
                res = spjs_QueryItems({"listName":"Stock Movement","listBaseUrl":"../..","query":qb.join(""),"viewFields":[strField]});
                if(res.count > 0){
                    item = res.items[0];
                            
                    if(item[strField]===null){
                        return false;
                    } else{
                        return true;
                    }
                } else {
                	return false;
                }
            }
          • #18697
            Alexander Bautz
            Keymaster

              If you don’t get any results when using item.get_item(“Job”).get_lookupValue() I suspect you might have many lookup columns and people pickers in this list?

              If this is true, the query will not pull back all these fields (only the first 7 I think). To workaround this issue, try going into list settings and change the order of the fields and move “Job” up over the other lookup or people picker columns.

              Alexander

          Viewing 3 reply threads
          • You must be logged in to reply to this topic.