ads

Sunday, September 8, 2013

Modify User Custom Actions Using JavaScript

The following example show you
how to  edit (appending icon to new custom action) a user custom action from  the drop-down menu on list items.



 <a onclick="modifyUserCustomAction(); " href="#">Modify Custom Action</a>
 
 
  <script>


var siteUrl = '/sites/site name';

function modifyUserCustomAction() {

    this.clientContext = new SP.ClientContext(siteUrl);
    var oWebsite = clientContext.get_web();
    this.oList = oWebsite.get_lists().getByTitle('list name');
    this.collUserCustomAction = oList.get_userCustomActions();
       
    clientContext.load(oList,'UserCustomActions','Title');

    clientContext.executeQueryAsync(Function.createDelegate(this, this.SetImage), Function.createDelegate(this, this.onQueryFailed));
}

function SetImage() {

    var customActionEnumerator = collUserCustomAction.getEnumerator();

    while (customActionEnumerator.moveNext())
    {
        var oUserCustomAction = customActionEnumerator.get_current();
           
        if (oUserCustomAction.get_title() == 'derege Custom Action')
        {
           oUserCustomAction.set_imageUrl('/_layouts/images/QuickTagILikeIt_24.png');
           oUserCustomAction.update();
          
            clientContext.load(oUserCustomAction);

           clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));
        }
    }
}

function onQuerySucceeded() {

    alert('Custom action updated for ' + this.oList.get_title());
}

function onQueryFailed(sender, args) {

        alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}
</script>

related content  
add user custom actions
delet user custom actions
Do you like this post?
Buy me a cup of coffe to show your appreciation!

No comments:

Post a Comment