troubleshooting Question

Sharepoint Designer Javascript - Getting The Value Of "Person Or Group" And "Lookup" Type Fiields.

Avatar of IanWood
IanWoodFlag for United States of America asked on
Microsoft SharePointWeb ApplicationsMicrosoft Server Apps
2 Comments1 Solution1453 ViewsLast Modified:
Hi

I'm using the following function I found on the internet to get the values of sharepoint fields:-

function getTagFromIdentifierAndTitle(tagName, identifier, title, option) {
  var len = identifier.length;
  var tags = document.getElementsByTagName(tagName);
  for (var i=0; i < tags.length; i++) {
    var idString = tags[i].id;
    var nameString = tags[i].name;
    // get selected radio button value only
    if (option == "value" && tags[i].type == "radio" && (identifier == "RadioButtons" && nameString.indexOf(identifier) == nameString.length - len)) {
      var tagParentHTML = tags[i].parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.innerHTML;
        if (tagParentHTML.indexOf('FieldName="'+title+'"') > -1) {
              var radioButtons = document.getElementsByName(nameString);
              var radioValue = "";
              for (var x=0; x < radioButtons.length; x++) {
                if (radioButtons[x].checked) {
                      radioValue = radioButtons[x].parentElement.title;
                  break;
                }
              }
        var o = document.createElement("INPUT");
        o.type = "hidden";
        o.value = radioValue;
          return o;
        }
    }
    // get radio buttons group
    if (tags[i].type == "radio" && (identifier == "RadioButtons" && nameString.indexOf(identifier) == nameString.length - len)) {
      var tagParentHTML = tags[i].parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.innerHTML;
        if (tagParentHTML.indexOf('FieldName="'+title+'"') > -1) {
              return document.getElementsByName(nameString);
        }
    }
      // all other input or select type
    else if (tags[i].title == title && (identifier == "" || idString.indexOf(identifier) == idString.length - len)) {
   
       return tags[i];
    }
  }
  return null;
}

it's working fine for most field types, but not for "Lookup" Or "Person Or Group",

I'm calling it with:

  var business_area = getTagFromIdentifierAndTitle("select","Lookup","Business Area","");

i've tried various combination now, but no luck.

Any advice please?

Thanks.

Ps Sorry for the lack of points. I've ran out.  Any help would be much appreciated!
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 2 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros