1

I'm using a function to grab the id from the url of the record and fetching numerous field values successfully. It seems to work fine for all fields except for people pickers. When I display the fields in an alert for testing purposes I am seeing the following:

"Joe's Bait Shop [object object]".

I am using js to clone records and usually grab values from the form using the id of the field, however, grabbing values from pp fields has got me stumped.

I've tried using SPServices $().SPServices.SPFindPeoplePicker and get the same result. Below are the two functions I'm using:

// Submit clone record
    function clientContxt(rID) {
        clientContext= new SP.ClientContext(); 
        targetList = clientContext.get_web().get_lists().getByTitle('TG Hosted');
        targetListItem = targetList.getItemById(rID);
        clientContext.load(targetListItem, 'Customer_x0020_Company_x0020_Nam', 'Account_x0020_Manager');
        clientContext.executeQueryAsync(onLoadSucceeded, onQueryFailed);    
    }
// Load list item fields
    function onLoadSucceeded() 
    {
        custName = targetListItem.get_item('Customer_x0020_Company_x0020_Nam');
        accountMan = targetListItem.get_item('Account_x0020_Manager');
        alert(custName+" "+accountMan);
    }

I've searched this forum and google for answers and can't seem to connect all the dots. Thank you.

EDIT
Here is the code for SPServices that I tried. When I use this I get an alert that is empty and my debugger comes up with this error. I am using the display form.

Object doesn't support property or method 'addEventListener'

var aMan = $().SPFindPeoplePicker({peoplePickerDisplayName: "Account Manager"});
var vaMan = aMan.currentValue;
alert(vaMan);
3
  • Can you post your SPServices code for me? I'm a lot faster with that. Is this code on your DispForm.aspx page?
    – Erin L
    Dec 31, 2015 at 16:30
  • See post edit above...
    – Ghoztrider
    Dec 31, 2015 at 17:13
  • Thanks. Can you clarify whether you're trying to get Account Manager from the field in the display form, or by fetching the item using the ID pulled from the URL? Or does it not matter to you which way it's done as long as you get the value?
    – Erin L
    Dec 31, 2015 at 18:24

2 Answers 2

1

The reason SPFindPeoplePicker isn't returning a value is because it's intended to be used in the New or Edit forms. If you only have one people picker on the form, you can use $("#SPFieldUser").text() to get its value.

0

I think you are trying to say Person or Group Column.
To get value from Person or Group column is same as lookup field.
Try using following code if it works for you.

function clientContxt(rID) {
    clientContext= new SP.ClientContext(); 
    targetList = clientContext.get_web().get_lists().getByTitle('TG Hosted');
    targetListItem = targetList.getItemById(rID);
    clientContext.load(targetListItem, 'Customer_x0020_Company_x0020_Nam', 'Account_x0020_Manager');
    clientContext.executeQueryAsync(onLoadSucceeded, onQueryFailed);    
}

// Load list item fields
function onLoadSucceeded() 
{
    custName = targetListItem.get_item('Customer_x0020_Company_x0020_Nam');
    accountMan = targetListItem.get_item('Account_x0020_Manager').get_lookupValue();
    alert(custName+" "+accountMan);
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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