0

I have a custom action where I will create a new item in the ecb menu for a document library and once clicked it will call a javascript function and there using ecma client object model I will checkout a document if the logged user is 'System account'. For other users no action is performed.

The following is the custom action and script code. This code works well in my development environment but when I deploy it in the testing environment I get

404 exception error ("Unexpected response from the server. The status code of response is '404'. The status text of response is 'Not Found')

What I found was when executeQueryAsync call is made in the script, the exception is fired. What might be the cause of this issue?

Custom Action code

   <CustomAction Description="Check out documents."
        Id="{B4C1A57C-F3B9-4873-96BC-17446E37FBA3}"
        Location="EditControlBlock"
        Sequence="0"
        Title="Check out items"
        RegistrationType="ContentType"
        RegistrationId="0x0101" >
<!--<UrlAction Url="javascript:alert('Item Id: {ItemId},\nList Id:{ListId},\nItem URL: {ItemUrl},\nSite URL:{SiteUrl}
                 ,{~site}
                 ,{~sitecollection}')"/>-->
<UrlAction Url="javascript:CheckOutItem({ItemId},'{ItemUrl}');"/>

Javascript code

 var libraryName = "Document library";

 var context = null;
 var web = null;
 var currentUser = null;
 var ItemId = null;

function CheckOutItem(itemId, itemUrl) {
try {
    alert(itemUrl);
    ItemId = itemId;        
    context = SP.ClientContext.get_current();        
    web = context.get_web();        
    currentUser = web.get_currentUser();        
    context.load(currentUser);        
    context.executeQueryAsync(Function.createDelegate(this, this.onGetUserSucceeded), Function.createDelegate(this, this.onFailed));
}
catch (e) {
    alert('CheckOutItem');
    alert("Error: " + e);
}
}

   function onGetUserSucceeded(sender, args) {
//alert(' Name:' + this._currentUser.get_title() + '\n Login:' + this._currentUser.get_loginName());           
CheckOutItems(ItemId);
RefreshCommandUI();
}

function onSucceeded(sender, args) {
alert("Checked out successfully.");
window.location = window.location;
}

  function CheckOutItems(itemId) {
try {        
    if (currentUser.get_title() == "System Account") {
        this.list = web.get_lists().getByTitle(libraryName);
        this.item = list.getItemById(itemId);
        this.file = this.item.get_file();
        file.checkOut();
        context.executeQueryAsync(Function.createDelegate(this, this.onSucceeded), Function.createDelegate(this, this.onFailed));
    }
}
catch (e) {
    alert('CheckOutItems');
    alert("Error: " + e);
}
  }

function onFailed(sender, args) {
alert(args.get_message());
}

closed as too localized by SPDoctor May 29 '13 at 7:38

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. If this question can be reworded to fit the rules in the help center, please edit the question.

  • When the exception happens "The service '/_vti_bin/client.svc' does not exist." is what i got in the console in chrome. How to fix this?. Any idea? – anantharengan May 22 '13 at 12:59
  • I am closing this question as the underlying problem was the configuration rather than the specific code you are using. Instead the new question you created covers it. If you think anything here is still relevant please add it to your other question. Thanks. – SPDoctor May 29 '13 at 7:37
  • Yea correct SPDoctor. – anantharengan May 29 '13 at 7:46
0

The client.svc is missing in the ISAPI folder. So I copied the client.svc file from another server and placed on this server. Now the exception is not coming but I have a different exception(500 error code exception).

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