I have a form where I have a lookup field displaying issue ids of same list. On selection of Issue id, Person field (Issue Assigned to) and other Lookup field (Function) to be prefilled. I have achieved this for other type of fields.

How to get values of Person and lookup columns?


Values for the Person/Group field are controlled by the user id from UPS. Display name will not work. Use the user ID and you will be able to prepopulate your user field.

| improve this answer | |

For Lookup Field,

  • To Get the selected Lookup value in the current form

    LItem.get_item("Internal Name of Lookup field").get_lookupValue();
  • To Set the selected lookup value to another Lookup field in the current form

    $("select[title='Lookup field Name']").val(LItem.get_item("Internal Name of Lookup field").get_lookupValue());

For People Field,

To Get the People Field value

Item.get_item("Intrnal Name of People field").get_lookupValue();

To Set it to a People field value in the current form

 var context = SP.ClientContext.get_current();
 var web = context.get_web();
 var user = web.ensureUser(LItem.get_item("Intrnal Name of People field").get_lookupValue());
var form = $("table[class='ms-formtable']"); 
var userField = form.find("input[id$='ClientPeoplePicker_EditorInput']").get(0);
var peoplepicker = SPClientPeoplePicker.PickerObjectFromSubElement(userField);
var loginName = user.get_loginName();
peoplepicker.AddUserKeys(loginName);},function(sender,args){ // on error

For more details check Auto-Populate the Lookup and People Fields in List form based on lookup selection in sharepoint

| improve this answer | |
  • Its getting the correct value for Lookup field but not setting the. It just sets it blank (from default value "(None)" – Sanjana Chhabira Jan 13 '18 at 2:39
  • For lookup field this worked : var check = ListItem.get_item("Functionn").get_lookupValue(); var allOptions = document.querySelectorAll("[title=Functionn] option"); [].some.call(allOptions, function(option) { if (option.innerHTML == check) { option.selected = "selected"; return true; } }); – Sanjana Chhabira Jan 13 '18 at 3:22
  • Have you checked the attached link! it set the lookup value if it already there?! – Mohamed El-Qassas MVP Jan 13 '18 at 8:27
  • For People field its giving an error - "SPClientPeoplePicker is not defined". Can you help? – Sanjana Chhabira Jan 13 '18 at 9:38
  • Yes, I tried the code from your link itself. Full code that you have given – Sanjana Chhabira Jan 13 '18 at 9:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.