0

I have a custom field "webPartId" in my page property

Whenever user clicks save, i want to update the field

I am not able to get any code snippets for that!

The closest i could reach is finding how to access the page properties via javascript / csom / REST api using below function

function getCurrentListItem(success, error)
{
   var context = SP.ClientContext.get_current();
   var web = context.get_web(); 
   var currentList = web.get_lists().getById(_spPageContextInfo.pageListId); 
   var currentListItem = currentList.getItemById(_spPageContextInfo.pageItemId);
   context.load(currentListItem);
   context.executeQueryAsync(
     function(){
        success(currentListItem);
     }, 
     error
   );
}
getCurrentListItem(
   function(listItem) {
       var webPartId= listItem.get_item('webPartId'); 
       console.log(webPartId);
   },
   function(sender,args){
        console.log(args.get_message());    
   }
);

Now i want to modify that property,

$("#saveWebPartId").click(function(){
//code to modify the page properties
});

Any client side snippet that can modify the page property is ok to me

  • 1
    Does the code snippet work? Do you get the correct value? If so can't you just call currentListItem.set_item('webPartId', '...'); currentListItem.update()? – eirikb Jun 14 '15 at 11:18
  • ya i figured that out Not sure why it is not coming in auto complete!! I typed currentListItem. and waited for chrome to show me list of functions and set_item did not appear! – Vignesh Subramanian Jun 14 '15 at 11:26
0

I figured out the way for this

 listItem.set_item('FieldName',valueToBeSet); 
 listItem.update(); 
 var context = SP.ClientContext.get_current();
 context.executeQueryAsync(Function.createDelegate(this,this.onQuerySucceeded), 
       Function.createDelegate(this, this.onQueryFailed));

This solved the problem

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.