Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

My task is to process selected items of some list. Can I change some field value from the client object model ?

I found some solution like this:

<?xml version="1.0" encoding="utf-8" ?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">



<CustomAction

Id="CAAlertRibbonButton"
RegistrationId="100"
RegistrationType="List"
Location="CommandUI.Ribbon"
Sequence="5"
Title="Alert Ribbon Button">

<CommandUIExtension>
<CommandUIDefinitions>
<CommandUIDefinition Location="Ribbon.List.Settings.Controls._children">
<Button
Id="AlertRibbonButtonId"
Alt="Alert Ribbon Button"
Sequence="5"
Command="CMDAlertRibbonButton"
Image32by32="/_layouts/images/menulistsettings.gif"
Image16by16="/_layouts/images/itdcl.gif"
LabelText="Alert Ribbon Button"
TemplateAlias="o1" />
</CommandUIDefinition>
</CommandUIDefinitions>

<CommandUIHandlers>
<CommandUIHandler
Command="CMDAlertRibbonButton"
CommandAction="javascript:
function resultCallback(result, value)
 {
 SP.UI.Notify.addNotification('Success!');
 SP.UI.ModalDialog.RefreshPage(SP.UI.DialogResult.OK);
 }

var ctx = SP.ClientContext.get_current();
var items = SP.ListOperation.Selection.getSelectedItems(ctx);
var myItems = '';
var i;

for (i in items)
{
myItems += '|' + items[i].id;
}

if(myItems != '')
 {
    // **I need call SERVER CODE here!**
 }" />
</CommandUIHandlers>

</CommandUIExtension>
</CustomAction>
</Elements>

and.. How can i call server code there? And one more question.. I need to place this button in manage elements section. How can i do this?

share|improve this question
    
Please just ask one question. If you have another question please create a new one. –  SPDoctor May 17 '12 at 18:43
    
if I write < in the ScriptLink, this is not legal in XML. Also I always have the problem, that in a Custom Action there is no web. Have you tested your code? –  user11738 Oct 31 '12 at 23:02

1 Answer 1

You can use somethig like this code in client object model for item property update

function UpdateSelectedItemProperty(internalFieldName, propertyValue) {
    var context = SP.ClientContext.get_current();
    var web = context.get_web();
    var selectedItems = SP.ListOperation.Selection.getSelectedItems(context);
    var selectedListId = SP.ListOperation.Selection.getSelectedList();
    var list = web.get_lists().getById(selectedListId);
    for (var i = 0; i < selectedItems.length; i++) {
        if (selectedItems[i].fsObjType == 0) {
            var listItem = list.getItemById(selectedItems[i].id);
            context.load(listItem);
            listItem.set_item(internalFieldName, propertyValue);
            listItem.update();
        }
    }
    context.executeQueryAsync(UpdateItemsSucceeded, UpdateItemsFailed);
}

function UpdateItemsSucceeded() {
    SP.UI.ModalDialog.RefreshPage(SP.UI.DialogResult.OK);
}

function UpdateItemsFailed(sender, args) {
    alert('Could not update items');
}

to place action to the manage elements section use this definition

<CustomAction Id="id"
                Location="CommandUI.Ribbon.ListView"
                RegistrationId="100"
                RegistrationType="List"
                Title="title">
    <CommandUIExtension>
      <CommandUIDefinitions>
        <CommandUIDefinition Location="Ribbon.ListItem.Manage.Controls._children">
share|improve this answer
    
thanks! you really help me. –  Alexey Apr 17 '12 at 13:14

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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