Wednesday, July 17, 2013

Fun with SharePoint REST and Javascript

Quick Update -- We've released our IntelliGantt for SharePoint 2013 pure HTML5+Javascript gantt chart. Install it and let us know what you think!

Exciting news as we are prepping the new web-based successor to IntelliGantt specifically for SharePoint 2013. We just passed a hurdle that other SharePoint 2013 developers using rest with javascript and the SP.RequestExecutor for cross domain calls should now. It's quite a mouthful, but if you are doing a SharePoint 2013 Provider Hosted App, then you'll know exactly what I'm talking about.


The crux of the issue seems to be that while you use one parameter set for straight ajax calls, when you use the SP.RequestExecutor, that object expects slightly different parameters. To wit:
instead of



type: "POST"

use

method: "POST"

and for the actual data package to post, instead of

data: JSON.stringify(item)

use

body: JSON.stringify(item)

For completeness, here is the block that I used to update via rest using javascript across a domain with the SP.RequestExecutor object:


  new SP.RequestExecutor(closureThis.appweburl).executeAsync(
     {
     url: closureThis.appweburl + "/_api/SP.AppContextSite(@target)/web/lists(guid\'" + listIdGuid + "\')/items(" + itemId + ")?@target='" + closureThis.hostweburl + "'",
     method: "POST",
     headers: {
       "accept": "application/json;odata=verbose",
       "content-type": "application/json;odata=verbose",
       "X-RequestDigest": closureThis.getDigestValue(),
       "X-HTTP-Method": "MERGE",
       "If-Match": "*"
     },
     body: updateBlock,
     success: function (data) { closureThis.updateDataObjectCallback(data); },
     error: spRequestorErrorHandler
     }
     );


Where closureThis is an object I use to store SharePoint variables and handle callbacks
Where updateBlock is the JSON.stringify(data) value



My updateBlock value looks like this:



"{\"__metadata\":{\"type\":\"SP.Data.TasksListItem\"},\"Title\":\"First Task\"}"

17 comments:

ragul ragul said...

Nice tutorial. Thanks for sharing the valuable information. it’s really helpful. Who want to learn this blog most helpful. Keep sharing on updated tutorials…
Best Devops Training in pune
Data science training in Bangalore

bavisthra said...

Study ExcelR PMP Certification where you get a great experience and better knowledge.

PMP Certification


Location 1:

ExcelR - Data Science, Data Analytics Course Training in Bangalore 49, 1st Cross, 27th Main BTM Layout stage 1 Behind Tata Motors Bengaluru, Karnataka 560068 Phone: 096321 56744 Hours: Sunday - Saturday 7AM - 11PM.

Comments

Anu said...

This information is impressive; I am inspired with your post writing style & how continuously you describe this topic.
DevOps Training | Certification in Chennai | DevOps Training | Certification in anna nagar | DevOps Training | Certification in omr | DevOps Training | Certification in porur | DevOps Training | Certification in tambaram | DevOps Training | Certification in velachery



Avijit said...

I have actually never perused such overwhelmingly great substance like this. I concur with your focuses and your thoughts. This information is extremely incredible. Much obliged.


SEO services in kolkata
Best SEO services in kolkata
SEO company in kolkata
Best SEO company in kolkata
Top SEO company in kolkata
Top SEO services in kolkata
SEO services in India
SEO copmany in India

eazyclasses said...
This comment has been removed by the author.
abid said...


Wow! Such an amazing and helpful post this is. I really really love it. It's so good and so awesome. I am just amazed. I hope that you continue to do your work like this in the future also.
data science course in guwahati

rocky said...

I would like to thank for the efforts you have made in writing this post. I am hoping the same best work from you in the future as well.
Python Training in Chennai

Python Training in Training

Python Training in Bangalore

Python Hyderabad

Python Training in Coimbatore


devi said...

wonderful article. Very interesting to read this article.I would like to thank you for the efforts you had made for writing this awesome article. This article resolved my all queries.
Data Science Training In Chennai | Certification | Data Science Courses in Chennai | Data Science Training In Bangalore | Certification | Data Science Courses in Bangalore | Data Science Training In Hyderabad | Certification | Data Science Courses in hyderabad | Data Science Training In Coimbatore | Certification | Data Science Courses in Coimbatore | Data Science Training | Certification | Data Science Online Training Course

Jayalakshmi said...

What an incredible article!. I am bookmarking it to peruse it over again after work. It appears to be an extremely fascinating theme to expound on.
java training in chennai

java training in tambaram

aws training in chennai

aws training in tambaram

python training in chennai

python training in tambaram

selenium training in chennai

selenium training in tambaram

deiva said...

Excellent Blog! I would like to thank for the efforts you have made in writing this post.
angular js training in chennai

angular js training in omr

full stack training in chennai

full stack training in omr

php training in chennai

php training in omr

photoshop training in chennai

photoshop training in omr

harshini said...

Thank you for posting informative insights, I think we have got some more information to share with you! Do check out Data Analytics Course

Anonymous said...

Awesome blog post,
Digital Marketing Video Course

Ramesh Sampangi said...

Really awesome blog. Useful information and knowledge. Thanks for posting this blog. Keep sharing more blogs again soon.
AI Patasala Data Science Course

Unknown said...

Uncommonly in ordinary extraordinarily captivating post. I was looking for such an information and partook in the experience of examining this one. Keep on posting. A responsibility of appreciation is for sharing.data analytics course in bhubaneswar

Unknown said...

Very nice job... Thanks for sharing this amazing and educative blog post! data science training in kanpur

360digiTMG.com said...

Data Science is a dynamic domain with a promising future, start your Data Science Course today with 360DigiTMG and become a Data Scientist without hassle.
best data science courses in chennai

priya said...

Thank you the sharing the most informative blog for us. It may helpfull for you all.

Selenium Training in Chennai
Best Selenium Training in Chennai