getFieldValue for lookups

Home Forums Classic DFFS getFieldValue for lookups

Viewing 5 reply threads
  • Author
    Posts
    • #24291
      Leonid
      Participant

        I have a multi-value lookup field “Groups” set as a dropdown. Use of

        getFieldValue("Groups")

        results in a delimited string of Values. Is there a function to get IDs or key/value pairs?
        I understand there is a people-picker syntax that does return a key/value pair for People Picker:

        getFieldValue({"fin": xxx, "key": yyy})

        Cant find yet what will work for a lookup field. Appreciate assist

      • #24299
        Alexander Bautz
        Keymaster

          Hi,
          I’m not sure what you mean by “multi-value lookup field “Groups” set as a dropdown” – is this some kind of third party field type or is it the default lookup field with multiselect turned on so you have two lists side by side – one with unselected options and one with selected ones?

          Alexander

        • #24301
          Leonid
          Participant

            Right, Alex, just a regular Lookup field named “Groups”, with enabled multi-value selection.
            The field is a lookup to another list. I’d like to pull not just selected values from the source list, but also selected items’ IDs.

            getFieldValue("Groups")

            only returns Values.
            Wondering if there is a DFFS function to get value pairs or IDs.
            I understand that if nothing else, I can run

            spjs.utility.queryItems()

            passing selected Values in CAML, but that seems too cumbersome just to get IDs.
            Please advise.

            Attachments:
          • #24304
            Alexander Bautz
            Keymaster

              You can use this function:

              function getMultiLookupKeyValue(fin) {
                  var a = [];
                  jQuery("#dffs_" + fin + " select:last option").each(function (i, o) {
                      a.push({ "id": o.getAttribute("value"), "title": o.innerText });
                  });
                  return a;
              }
              // Call it with the fieldinternalname
              getMultiLookupKeyValue("LookupColumn2");

              Alexander

            • #24306
              Leonid
              Participant

                Thanks Alex, works like a charm! What exactly “#dffs_” does at run time? – back to DFFS API 🙂

              • #24311
                Alexander Bautz
                Keymaster

                  This is just a jQuery selector looking for the table row with ID = “dffs_FieldInternalName”. This ID attribute is inserted by the DFFS script and this is why it has the dffs_ prefix. This is not really a DFFS functionality, it’s just “traversing the DOM to find the element you are looking for” – you don’t need to use jQuery if you want to use plain javascript, but it’s most likely easier to use jQuery. You can read about the different jQuery methods here: https://api.jquery.com/category/traversing/

                  Alexander

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