Friday, December 18, 2015

How to access a custom field of a list using REST

<script type="text/javascript">
SP.SOD.executeFunc('sp.js','SP.ClientContext',update);
var returnedItems;
function update(){

var context=new SP.ClientContext();
var list=context.get_web().get_lists().getByTitle('Documents');

var caml = new SP.CamlQuery();
caml.set_viewXml("<View><Query></Query></View>");
returnedItems=list.getItems(caml);
context.load(returnedItems);
context.executeQueryAsync(onSucceededCallback,onFailedCallback);

}

function onSucceededCallback(sender,args){
alert();
var enumerator = returnedItems.getEnumerator();

while(enumerator.moveNext()){
var listItem=enumerator.get_current();
var myfield=listItem.get_item('MyField');

}
    }

function onFailedCallback(sender,args){
alert("Failed to connect:  "+args.get_message());
}
</script>

No comments:

Post a Comment