Get user value from list column in Javascript

Hi ,i need to get the value of a user column via JS, i try this

var Part = oListItem.get_item('Attendees').get_lookupValue();

Any idea?

August 4th, 2015 2:46pm

Hi,

The following code for your reference, please add the code into a content editor web part.

<script language="ecmascript" type="text/ecmascript">
var listItem;
var list;
var clientContext;
function getFieldUserValue() {
	this.clientContext = SP.ClientContext.get_current();
	if (this.clientContext != undefined && clientContext != null) {
		var webSite = clientContext.get_web();
		this.list = webSite.get_lists().getByTitle("CustomList");
		this.listItem = list.getItemById(1);
		clientContext.load(this.listItem);
		this.clientContext.executeQueryAsync(Function.createDelegate(this, this.OnLoadSuccess), Function.createDelegate(this, this.OnLoadFailed));
	}
}

function OnLoadSuccess(sender, args) {
	var fieldUserValue = this.listItem.get_item("Attendees");
	if(fieldUserValue.length==null){
		alert(fieldUserValue.get_lookupValue());
	}else{
		for (var i = 0; i < fieldUserValue.length; i++) {
			alert(fieldUserValue[i].get_lookupValue());
		}
	}	
}
function OnLoadFailed(sender, args) {
	alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}
</script>
<input id="btnGetFieldUserValue" onclick="getFieldUserValue()" type="button" value="Get User Column" />
Best Regards

August 5th, 2015 5:58am

Hi i get this error:

The property or field has not been initialized. It has not been requested or the request has not been executed. It may need to be explicitly requested.

Free Windows Admin Tool Kit Click here and download it now
August 5th, 2015 6:52am

Hi 

As per the error one of the property that you are trying to access is not loaded. 

load the property before execute query method. 

http://sharepoint.stackexchange.com/questions/30828/the-property-or-field-has-not-been-initialized-it-has-not-been-requested-or-the

http://sharepoint.stackexchange.com/questions/130512/uncaught-error-the-property-or-field-has-not-been-initialized-i-have-tried-man

August 5th, 2015 7:01am

Hi,

Please check the "Attendees" field internal name, and check whether you modify the list title name and item id of the code above.

Best Regards

Free Windows Admin Tool Kit Click here and download it now
August 5th, 2015 8:55pm

Hi gohberto,

Any update?

Thanks

August 13th, 2015 11:29pm

Hi ,

i tryed some script ma no one is good for me!

Bye


  • Edited by gohberto Friday, August 14, 2015 8:52 AM
Free Windows Admin Tool Kit Click here and download it now
August 14th, 2015 8:52am

Hi,

Did you try to debug my code above? It works for me.

My test list name is "CustomList", field column name is "Attendees", item id is "1".

I suggest you create a new list to test it.

If the issue still exists, please try to debug the code using IE F12 developer tools and see which line of code occur the issue.

Best Regards

August 14th, 2015 9:23am

Hi this is Working for me, it is good for multiuser field

function onQuerySucceeded(sender, args) {
    var listItemInfo = '';
    var listItemEnumerator = collListItem.getEnumerator();
        
    while (listItemEnumerator.moveNext()) {
        var oListItem = listItemEnumerator.get_current();
        
        var result = '';
        var members = oListItem.get_item('Attendees');
        for(i=0; i<members.length; i++)
        {
            var member = members[i];
            result += member.get_lookupValue()+';';
        }  
 
       
        listItemInfo += result ;

Free Windows Admin Tool Kit Click here and download it now
September 8th, 2015 2:58am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics