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

I am a young developper, and the marketing department of my compagny need a approval workflow that send a email with buttons or links stated "Approved" or "Rejected".

I have a document library, and every item has a Status (Approved/Rejected).

Here's an article on the subject : http://community.corasworks.net/blogs.aspx?CWFrameSource=http://community.corasworks.net/blogs/fromthefield/archive/2009/07/21/build-one-click-approval-into-workflow-emails.aspx

However, the first step is not clear, and I either need further specification on "leveraging a SharePoint web service for updating a list item", or need to be sent on a new path.

I already know how to get the link to modify all the proprierties or the current item : (http:// My Site / My list / Forms"EditForm.aspx?ID=[%Current Item:ID%] ), and it work well.

...But what I really need it to set a value just by clicking on a link.

To Resume : Can I have a "Update List Item" link, with a certain value been set? In effect, I need to do exactly the same thing that in the Action step "Update List Item", but in a single link that I can put in a email (from a workflow).

Thank you a lot for your time.

Simon P.

share|improve this question

3 Answers 3

up vote 1 down vote accepted

My approach would be: Create a new page (e.g. in a wiki page library), then use the Javascript Client OM to update the list item on page load. This would be the javascript code:

<script type="text/javascript">
function updateItem() {
  try {
    var context = new SP.ClientContext('/sitecollection_server_relativ_url');        
    var web = context.get_web();
    var list = web.get_lists().getByTitle('YOUR_LIST_DISPLAY_NAME');

    // get the item id to be updated from query string
    var itemId = getParameterByName('id');
    // get the new status from query string
    var newStatus = getParameterByName('status');

    var item = list.getItemById(itemId);
    item.set_item('Status', newStatus);
    item.update();
    context.executeQueryAsync(Function.createDelegate(this,     this.updateSucceeded),Function.createDelegate(this, this.updateFailed));
  }
  catch(ex) { }
}

function updateSucceeded() {
  // do something
}

function updateFailed() {
  // do something
}

// function to get parameter from query string
function getParameterByName(name)
{
  name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
  var regexS = "[\\?&]" + name + "=([^&#]*)";
  var regex = new RegExp(regexS);
  var results = regex.exec(window.location.search);
  if(results == null)
    return "";
  else
    return decodeURIComponent(results[1].replace(/\+/g, " "));
}

// needed, so SharePoint will execute your function after the client object model is available
ExecuteOrDelayUntilScriptLoaded(updateItem, "sp.js");
</script>
share|improve this answer

I know this is old, but to put spaces, you type %20 instead of the space

so: my document id would be: my%20document%20id

Perhaps this will help someone else on a search..

share|improve this answer
    
Nice answer Dave! And welcome to SP.SE! I hope you continue to contribute to our site! –  Benny Skogberg MCSA Nov 18 '13 at 20:21

I resolved my issue... Kind of. Here's my process.Thank you Marco, your answer set me on the right track.

First, I uploaded a html file with your code (edited to my library and variable). I then created a webPart "content editor".

Clicking on "Modify content", I set the part with the path of my html file I uploaded in my library. This apparently use the html in the document, without modifying it (since my sharepoint site had a tendency to modify html code in it).

In the code, I created alert(" ...") for failure or success. So, when I click on the document library, it run the code.

What your code do, is that when the URL of the site is called, from anywhere, it load the html in the document on that list. I just have to add ?ID=my_document_ID&Status=my_status after the url of the document library.

And it work.

To an extent. If I have spaces in the document library's name, I found out it does not work.

I did a lot of experimentation on this, but I'm in the process of learning HTML and Javascript, so maybe there is a nomenclature (a way to write) that I'm not aware of, but that's as far as I've gone.

Thank's again for your response.

share|improve this answer

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.