Hi there,
I have a question regarding javascript and the security validation.
I have created a custom action, which should update one field in all marked documents by the user. But when I do the update, I got this error message:
"The security validation for this page is invalid. Click Back in your Web browser, refresh the page, and try your operation again."
I know, I could AllowUnsafeUpdates, if I were using C#, but actually I can only use JavaScript at this stage. Or does anybody know, how to allow this or switch to C# in this area?
Here is my custom action:
<?xml version="1.0" encoding="utf-8"?><Elements xmlns="http://schemas.microsoft.com/sharepoint/"><CustomAction
Id="GrolmansJavaScriptFile"
ScriptSrc="~site/_layouts/SharePoint-Z-Drive-Project/gg1855.js"
Location="ScriptLink"></CustomAction><CustomAction
Description="Approve Documents"
Title="Approve Documents"
Id="RibbonDocumentsManageApproveDocuments"
Location="CommandUI.Ribbon"
RegistrationId="10000"
RegistrationType="List"
Sequence="0"
xmlns="http://schemas.microsoft.com/sharepoint/"><CommandUIExtension xmlns="http://schemas.microsoft.com/sharepoint/"><!-- Define the (UI) button to be used for this custom action --><CommandUIDefinitions><CommandUIDefinition Location="Ribbon.Documents.Manage.Controls._children"><Button Id="Ribbon.Documents.Manage.ApproveDocuments"
Command="{4E2F5DC0-FE2C-4466-BB2D-3ED0D1917763}"
Image32by32="~site/_layouts/Images/SharePoint-Z-Drive-Project/approve_document_32x32.png"
Image16by16="~site/_layouts/Images/SharePoint-Z-Drive-Project/approve_document_16x16.png"
Sequence="0"
LabelText="Approve Documents"
Description="Approve Documents"
TemplateAlias="o1" /></CommandUIDefinition></CommandUIDefinitions><CommandUIHandlers><!-- Define the action expected on the button click --><CommandUIHandler Command="{4E2F5DC0-FE2C-4466-BB2D-3ED0D1917763}" CommandAction="javascript:void(ApproveDocuments());" /></CommandUIHandlers></CommandUIExtension></CustomAction></Elements>And here is my JavaScript code file:
function ApproveDocuments()
{
var siteUrl = '/';
var clientContext = new SP.ClientContext(siteUrl);
var currentlibid = SP.ListOperation.Selection.getSelectedList();
var currentLib = clientContext.get_web().get_lists().getById(currentlibid); //Gets the current Library
var selectedItems = SP.ListOperation.Selection.getSelectedItems(clientContext);
for (var i in selectedItems) {
currentLib.getItemById(selectedItems[i].id).set_item('DocumentStatus', 'Approved');
currentLib.getItemById(selectedItems[i].id).update();
clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));
}
}
function onQuerySucceeded()
{
alert('Document approved:' + newListItem.get_id());
}
function onQueryFailed(sender, args)
{
alert('Document approval failed: ' + args.get_message() + '\n' + args.get_stackTrace());
}Any idea, how to perform the update on the selected items?
Thanks for any hint.
Dennis