Fabian Williams SharePoint Blog

Solving problems with SharePoint day and night

HELP: Unable to Create List using SharePoint 2013 REST API in SPD2013

Précis

So, I am took up @Office365 on their offer of help, but then they directed me to the forums because they said the limitation of twitter made it difficult to respond to my tweet for help

image

So i set about doing that this morning, however even the forums have limits when you try to paint a thorough picture of your problem using screen shots due to image sizes. see here

image

So, i will just blog it and point back to this blog post using the Forum as the initial pointer for anyone who wants to help, fortunately WordPress give me more freedom in images and i can be verbose. So here goes…

Problem Stated

The objective is to Create a new List in SharePoint Online Wave 15 via REST https://site/_api/web/lists and then passing the necessary headers. Also, if I do a GET using the same headers, IT WORKS, this only happens on POST with the addition payload of Request Content(Body) that I am sending, but in Fiddler "using" the same payload, I can create my list. I’ve blogged about this topic and how I go about doing REST via SPD and Fiddler here and here and here, the first and last are probably most appropriate for this line of question. Below are some screen shots of what I am experiencing now. I thank you in advance for any assistance you can provide.

Below are the Request Headers

1

Below is me constructing what will be the Request Content (Body) but to get the desired feel, I had to put the __metadata property inside its own dictionary object to get the curly braces and key value pair, you will see below

2

Below you will see me wrapping this variable inside another to get {‘__metadata’:{‘type’:’SP.List’} to come out properly

3

Next you will see my call to HTTP web Service properties

 4

Next you will see my results. this is my parsing the JSON returned in the Response Code and Response Body

 5

Proof that the same thing works in Fiddler

Here is me doing the same thing in Fiddler. and i also updated my Digest so that it would be current because i know it expires after a while

 

image 

and

image

and the list in O365 is created here

image

 

Update Section

This section will be filled with things I have tried either on my own or on suggestions.

The first thing i will do is take Hugh @hughajwood Wood suggestions and use a simple example on a post I actually praised earlier and do just a simple Add of a List Item in Office 365, i will dubb it TryAlpha

Try Alpha – 09/06/2013 1212 HRS

So the first thing I did was to make the headers as the post describe, to keep things simple i used the exact nomenclature

image

now wrap that header into a Dictionary header named __metadata and add a Title field

image

next use those headers to make my REST call

image

and we can safely say that using the REST API for List Items work. Let me also make some qualifiers

  1. Before doing this, I updated my X-RequestDigest to get a new value and I updated my requestHeaders variable, that was the only thing i did

image

End TestAlpha

Begin Test Bravo

So, I got some information from Paul Schaeflein @paulschaeflein He suggested that rather than hardcoding the Digest Information [which I know also expires after a while, and that is why whenever I run the WF, I redo the contextinfo URI and get a new one] I should do a POST insider my Workflow to get the Digest Information and THEN extract the X-RequestHeader value inside a variable and use it. The thought being, it will be more current than hard coding it, and Pauls Point was that it is safer from a security standpoint if SPD was preventing ‘malicious’ usages or hardcoded values.

Well In the end, it didnt work either. here is the story

Big Picture

image

In more detail I created one header to get the ContextInfo Information i.e. No Digest information was used in that one, and then I set the value coming from the JSON WebContextInformation object mapping to the Digest into a Variable called str_FormDigest.  I then used that Variable in another Header that I have specifically for the POST that I will use to create the List Item. See below

image

And for good measure I logged the output of the Digest so i know it works. here is the Digest Info and another failed attempt

image

End TestBravo

 

 

 

 

 

 

Summary

Any help is appreciated, I will ask that you post your feedback in the comments on this blog and i will update the Ticket in the Forum pointing back to this blog post.

 

Here is the Forum Thread: http://social.msdn.microsoft.com/Forums/en-US/dd9932f5-1e3f-416f-8f0b-e8ab2b792ba1/unable-to-use-spd-2013-and-call-http-service-to-create-a-new-list-in-spo-via-rest

 

 

del.icio.us Tags:

Thanks in advance

Advertisements

September 6, 2013 Posted by | JSON, Office 365, REST, SharePoint 2013, SharePoint Designer 2013, SQL Server | 8 Comments

Creating a SharePoint Timer Job using SharePoint Designer 2013

What do i really mean?

Now that I have got your attention with that eye catching title, let me expand and qualify it.  So, what I will be doing exactly is

  1. Inspecting a List (a Task List actually) for Tasks that are Due and Overdue.
  2. I will be checking them nightly (every 24 hours to be exact)
  3. If task are Over Due, then I will take ‘some’ action on them, in this instance, I will be changing a KPI field but this can be quite exhaustive based on your own particular use case. see below for one i have in mind.
  4. Pause the Workflow for 24 hours and Repeat.

By the way, this CAN also be used in SharePoint Online

Use Case

In this use case I have been charged to monitor a Task list (multiple task list from varying SharePoint Sites/ Site Collections) and aggregating them. Once complete, then we need to serve up the tasks that are overdue into a KPI dashboard and send the email link to managers of those offending taskees.

For my POC demo here I will show how to get 1 Site Collection but to get multiple all you have to do is make a separate REST call to that particular Lists API, and the rest is easy.

Pre-Requisites and Technologies Used

In this example I am using an On Premises SharePoint 2013 with Workflows enabled, I am also using SharePoint Designer 2013 as well, that is if for tooling. i.e. NO CODE.  I will be using the SharePoint 2013 REST API to read the SharePoint Task Lists as my Entry Point URI. The generic url will be /_api/web/lists/getListByTitle(‘’)/items">/_api/web/lists/getListByTitle(‘’)/items">http://<sitename>/_api/web/lists/getListByTitle(‘<listNameHere>’)/items which fetches List Items from a Named list using oData. Now by default this will be returned to your in XML, so in order to use this in SharePoint Designer which requires JSON inside the Dictionary Object (see my post here if you need a refresher on that) you will need to modify the headers to accept JSON using the Accept Headers. The rest is a matter of using Loops to iterate through the List Items returned, and pausing for the time allotted.

Approach

As usual I put my URI inside a Variable to obscure the name & any API Keys if any, this time there was no need but it just makes for better programming especially if there are a lot and I want to swap them out from time to time without affecting the core program

image

the full list of properties from the Call HTTP web service is located below since it is truncated in the image

image

The Request Headers are “Accept: application/json; odata=verbose” and you can place that into a string type as well and call it into the HTTP Web Service Properties as well inside a Workflow Dictionary Variable

image

Once you have done that, then as seen in the first image and in my previous blog post on the same topic, you parse the JSON results to get the part of the dataset that you want, in this case i want what is under the “d/results” node and to do that I use the Get Item from Dictionary and parse out what i need then i count the items for good measure, save the “Count” as a variable to be used as my upper bound in my Loop Counter and log it out.

Do Business Logic

After setting up the stage to get the URI, return the JSON data, Parse It to the Node you want, and get a Count, the next thing is to do the business logic.

What you will see below in the image is us using the Variable Count as the upperbound in our Loop and then getting the JSON data into Local Variables to be manipulated in the Workflow Logic.

//MY SOAPBOX

So, i have been talking about this for a while as most people who have known me for a long time, know be because of my work and efforts in SharePoint BCS.  But i have actually moved my thoughts in some aspects to what BCS allows (even in 2013) and what Workflows gives you interms of interacting with External Data. You see my point is, if you do not need to look at that data, i.e. External List, or need to Search on that Data i.e. External Content Type as a Content Source, I THINK that it is to your best interest from a simplicity standpoint, a performance standpoint, best of breed standpoint… to do this as a Workflow calling External Web Services and manipulate the data how you want and then get rid of it (i.e. the Variables) when done. That way the data is only used for its intended purposes then goes away.

//END SOAPBOX

Back to our story, what we do next is inspect the Due Date and use Conditional Statements to affect changes to the Fields for what you need. in this instance I am updating a KPI field based on how far along or how overdue a Due date is on a Task List. Now the Use case here is that I can do this on Any Amount of List both On PREM and in Office 365 in the same logic, I have Scale and Scope down to a Tee 🙂

 

image

 

The logic loops through each item does a Check and then updates the loop counter until it hits the “Count” variable number then exits. Since this is a Timer Job then the next thing we need to do is Pause it and wait, see below

image

Now, this workflow was designed as a Site Workflow so it can be ran independently of any Library or Lists and this guy can run forever.

Summary

So the next time someone ask you to Do a Timer Job for them, especially if they say they want it on Office 365 (SharePoint Online) and it involves a use case similar to mine or at the very least is looking at affecting changes to a List/Library, consider doing a Site Workflow with Conditional Logic and Pause Duration. Its really is that simple.

If this was being done in SharePoint Online, you would also need to capture and pass along the oAuth Tokens FedAuth and rfTa in your dictionary object.

Cheers and Happy SharePointing

September 4, 2013 Posted by | JSON, Office 365, REST, SharePoint 2013, SharePoint Designer 2013, SharePoint How-To, SharePoint Online, Workflows | , , , | 13 Comments

SharePoint Saturday New York 2013 Wrap-up

Praises

Year after year the organizers and volunteers that put on SharePoint Saturday New York City #spsnyc do an amazing job and the intensity and excellence keeps getting better year after year.  Fantastic Job Rebecca “Becky” I, Greg G, Jason G, Tasha S, Tom D, Brandon B, Casey S, and the rest of the crew too many to name.

This year it felt like on all level it came together even with the late lunch 🙂 The audience was exceptionally knowledgeable and engaging, we had fun while learning; i guess it helps that I actually have been seeing them for many years know and we treat each other like extended family.  Even though next year we will be in a new Venue, I will miss the Microsoft facility across form the Hilton where the Halal GUys have their truck.

Regarding my Preso, Deck, Session Information

So, as noted in my presentation, and for those of you that know the way I deliver sessions, I do a lot of demos, hardly any slides. This time however, my session was based on a 2 part blog post I did, I requested that my session attendees not take notes because the blog post will be more information that you had in the session, so please pick it up here

Finally a SharePoint Designer that Developers and BAs will Love – This is the Part 1 of what would have come before the session you sat in and

Part 2 of Finally a SharePoint Designer that Developer and BAs will Love – This is reflective of the session you had

Thank you all for attending, hope to see you again next year.

Cheers.

July 29, 2013 Posted by | JSON, Public Speaking, REST, SharePoint 2013, SharePoint 2013 Workflows, SharePoint Designer 2013, Where is Fabian | , , , | Leave a comment

Coming soon: SharePointFabian Blog Mobile App

What’s my Motivation?

So, we can all agree that as each passing day goes by, our technology spigot comes to us via a mobile device [iDevice, Android Device, Microsoft Mobile Device, etc], so with that in mind I wanted to (1) start creating Mobile Apps (2) Learn how to do the first objective via creating my first Mobile App to showcase my Blog.

What was my approach

When taking on a new challenge, especially one where you are totally unmatched i.e. low to no prior knowledge on the specifics, then you use what you know to support what you don’t know. What do i mean by that? well in my case, I know C#, ASP.NET, MVC, so I try to use that as an approach to bridge getting a Mobile App created. Now, I will also say that recently I started to dive deep into HTML5, CSS and JavaScript as a way to also master SharePoint’s evolution into more Client Side Development, thank God, because that knowledge of JavaScript really panned out, I could whip out JS quite easily in my MVC code.

So, to wrap up this section, I talked to folks who have done this before from the SharePoint Community, and I bounced my App that I already built in HTML5, CSS, and JavaScript off them and they all said the same thing, “…its functional, but its ugly…” or words to the same effect.  Bart @Bart_tubalinal Tubalinal suggested that just take my HTML5/CSS/JS files and use a tool called PhoneGap (now called Cordova) to make it a Native App that can be consumed by IOS, Android and WindowsPhone. Now, that sounded like a great Idea, until i realized that PhoneGap didn’t give me an easy way to make my solution look petty i.e. I still needed to “sexy it up” So I spoke to Chris @LoungeFlyz Johnson (CJ) and asked his advice, after all he has this awesome App “My Trips” that plugs into TripIt’s API and allows you to well… take a look here in the marketplace for more detail. Well he turned me on to Sencha Touch 2 (@sencha) which takes ‘functional’ developers like me and puts some nice themes, buttons, panels, etc, in front of my code, then use PhoneGap to wrap it.

NB: I will do a separate blog on that journey of how to take a HTML5/CSS/JS App port it into a Sencha Touch 2 App then port that to a PhoneGap Solution then package that to the Microsoft Marketplace

So, that is/was my approach

Where is the App Now?

So the App is in the Validation phase of the Microsoft Marketplace and it is set to Publish Automatically, as soon as it does, I will tweet it. Mind you this is my first attempt 🙂 and ITS FREE, so you are getting exactly what you pay for LOL, nah JK, its pretty good for a first attempt.

for now, here is it working in a short demo video: SharePointFabian Blog Mobile App

and in the browser its just plain old MVC with JavaScript

ProofWorkingInIISUnderSameFolderStruct

What’s Next

So what am I going to do with this new fountain of budding knowledge? Well, I am going to first begin by tackling some stuff in SharePoint that not only will satisfy “DemoWare” solutions but should have some meaningful impact as well, for instance

  1. Visually Navigate Easily (icons, line graphs, actions) Workflows from a SharePoint Library using CSOM, REST and OData to adjudicate them without going into SharePoint by using Push Notifications
  2. and more stuff, i cant just put all my ideas out there can i 🙂 ?

Outside of SharePoint I do have my @TunnelViz App that I will be refactoring next since its already developed in HTML5/CSS/JS and that will be out soon. But expect some SharePoint Saturdays and other Conference Talks on Mobile Apps for SharePoint, as far as I know there are very few people doing Mobile Apps targeting Windows Device, so either (1) the market place will determine that there is no need for anything like that [and based on my struggles trying to figure out how to use Sencha with PhoneGap, I’m beginning to think that may be true] and my sessions wont get picked up or (2) Ill have a few others out there that do SharePoint Mobile Talks like Jeremy @jthake Thake did at TechEd

Till, then.. cheers.

July 8, 2013 Posted by | Client Side Coding, MobileApps, PhoneGap, Sencha, SharePoint 2013, Visual Studio 2012 | 1 Comment

How To: Create SharePoint 2013 Workflow App-Site Columns to Fully Deployed App using Visual Studio 2012

Précis

*** Feel free to skip this section unless you want background information on the genesis of this blog post***

Good day all, to appreciate this blog let me set the stage of my day. Two days ago, I put together a PowerShell Script that laid down the SQL Bits, SharePoint Bits, Configured a slew of Service Application, Configured Central Admin, as well as 4 Web Apps for sites, and also deploy Workflow Manger 1.0 and Register my Site collections, needless to say I was very pleased. To put this NEW Dev Rig to the test, decided to live up to my promise of duplicating a previous post done in SharePoint Designer, whereby I demonstrated how to use SPD 2013 to do complex workflows that could only be done in Visual Studio in SharePoint 2010. My spin on it was to do it all as a SharePoint Hosted ALL in ONE App in SharePoint 2013.

So, lets go to the end then Ill work my way back.  I found out when I tested my solution in my On Prem environment that it wasn’t working as designed, by that I mean:

  • My Assets Deployed
    • It installed all my Site Columns
    • It installed my Content Type
    • It installed my List Instance
  • What It didnt do
    • I could only get to the App URL by using the Account I used in Visual Studio to create the Solution, even though the other account (my own named fabianwilliams account) which is also a Site Owner in the Site it was Deployed to.. returned “cannot display this page” error
    • Even when I created or uploaded a document to the Library under the Content Type, There was NO workflow to fire off… “it” said “no workflow was defined for that Library, Folder, Document, or my Content Type” or something to that effect

So, that struck me as Odd, I tried it a few more times by breaking up the Provisioning of Assets piece into its own solution, and the Workflow in another, didn’t make a difference. SO, I decided to COPY MY CODE VERBATIM to my SharePoint Online Developer Tennant Account and guess what… IT WORKED THERE.

So this blog will chronicle the start from an On Prem solution and eventually copying the code to a new Visual Studio Solution targeting my SharePoint Online Account where it worked as Designed.  Ill either try to figure out why it didn’t work, or since I have a PoSH script, just review the script, make changes, Kill my Farm and Redo it.

UPDATE: 5/26/2013 0953HRS – So after a few hours sleep and thinking about why it didnt work, I tried just doing a regular Workflow App in Visual Studio and It worked, so it may NOT BE my Workflow Manger, indeed, my SharePoint Designer 2013 Workflows also work. So perhaps its my App Model Service Application that is Busted!!!, Ill look into it.

 

Approach

This is going to be a LONG post, especially because as you now I am verbose in my blogs, and I take lots of screen shots. So you may need to do this in a few sittings lol, or maybe it will end up being like a great novel.

Solution Design

  1. Open Visual Studio and Create a Project using the “App for SharePoint” project template.
  2. Create Folders to House the following Artifacts I will be creating
    1. Site Columns
    2. Content Type
    3. List Definition
  3. Create a List/Document Library based on the Assets in #2 above
  4. Create a Workflow based on the Instance in #3 set to begin manually and on Item Created event
  5. Point the AppManifest file to the Library Instance

Get your Site Columns squared away

Whenever I deliver solutions for clients, I absolutely always, unless told otherwise, create my own Site Columns, Content Types if necessary, and List/Library Instance when I am using Visual Studio to build and deploying my solution as a WSP. I do that to ensure that my columns and other assets are UNIQUE in the environment firstly, and second, it makes my solution very portable. So, its not surprising that in my example here I will do the same.

So, open up Visual Studio and Begin a SharePoint Apps “App for SharePoint 2013” project

image

Change your project from Auto Hosted to "SharePoint Hosted” and just validate your Connection for warm fuzzy feeling.

image

When you are done you should get a brand new shiny project as you see below

image

Create your Site Columns

Next I will add a few site columns to aid the process, there are a few these, and what I am trying to illustrate in this blog is the different kinds of Site Columns you can create and what the defaults are, as well as a few customized options you can make.

image

By default when you add a Site Column it adds an Elements.xml file that will set for Text type with limited information, I added more and changed the type to person (User & UserMulti), number, Choice, for a few of them.

Here is an example of what the default added site column looks like

image

Here is an example of what a few Site Columns look like after I modified it for text entry. You will notice that I have additions for StaticName, Description and whether or not the Field is Sealed, meaning can you edit it in your Site Columns once the solution is deployed.

image

Here is one that is modified for choice column. You will notice there are options here to allow or dis-allow FillInChoice as well as the available choices and the default one if none is selected.

image

Here is for Number. Key takeaway here is the Minimum and Maximum values, Decimal option. You will notice here that the Required is set to TRUE in this one.

image

 

Here is one for People. People is a little different from the rest in that it affects display in many ways. the Type can be (1) User or (2)UserMulti depending if you want to allow for multiple user selection in a single field. This can be because you want to do Parallel or Serial Approval with a bunch of folks denoted in a single field. In addition, the ShowField option there will show Presence Information if Lync/OCS is present.

image

and in the end the field that the Workflow will update when i is approved or rejected is this one, another Choice Field that has some meaning for us in the end.

image

Create your Content Type

Next you will make a Content Type to house all these Site Columns.

image

Next choose the template that this content type will be based off

image

Now you get to define what this Content Type will look like, you add columns from which you previously created as well as define other parameters as you see below. By clicking on the “Content Type” tab, you can set the Name, Description and Group where the CT will be stored as well as a few more options.

image

Now an all important step here is how you can add “Additional” columns in to your Content Type in addition to what will be there by default based on the one you inherit from. Here is where you will select from the previously created Site Columns. The task simple, just begin typing and you will see it finding the ones you want.

 

image

Finally your finished product will look like below when you have located all the ones you want.

 

image

Now you may not see the significance of all the above work, and you discount it as not a ‘big deal’ but If you have EVER done this in previous version of SharePoint you will understand that you had to do this all by hand i.e. now UI Tooling, so the experience was to create all this by XML as you see below, which is still there for you behind the scenes, but now you get to do it in a tool

image

Create your List Definition and List Instance

Finally its time to add the last piece of our artifacts, the List Definition, see below, notice also the creation of our Site Columns and Content Types to the Right in the Project Solution

image

As with the Content Type there are a few configurations we need to do such as telling the Definition what kind of List/Library to inherit from. Normally I would usually do Document Set because usually I find that its NOT just one document asset they have that is a part of the Business Process Re-engineering effort but a slew of them. But for simplicity here i elect Document Library.

image

and what template to use. Now again, if you had a template that was already done that had all the information they need you can put it here. Normally, I take the “Paper Document” and make an Electronic version here OR I take the electronic version and either

(1) Strip out the Fields that I will elevate to a Site Column in the Content Type from the document or

(2) Use Word Parts such that when the Document Information Panel (DIP) asks for the Metadata information, it AUTO POPULATES the fields in the document as well. Up to you.

image

and we finally tell the list definition to use the content type we created earlier which of course has our site columns included. So this is quite easy right and you can see the logical flow here. By clicking on the Content Type button, you select the Content Type you earlier created and it will automatically put in the Fields that you selected.

image

We also need to clean up our List Name and description as well as note the name of the List Instance because that will be the start page for our App Manifest so we can be taken directly to the List to add and item so the workflow can work

image

Now we almost to the end, we need to add a Workflow to our project and name it accordingly.

Create our Workflow – Finally huh 🙂

Now we add our Workflow Item to our Project.

image

Next again, you will need to configure a few steps such as what kind of workflow. Obviously we want a List Workflow for our project because we just spent all that time creating Site Columns, Content Types, and a List Definition to do it.  So name your Workflow and be on your way.

image

what it will run on, that is the List instance we created earlier from our List Definition. Now the Project knows about our List Instance that we created, so we just select it from the drop down list and in this case we want NEW instances of a Workflow History List as well as its OWN new task List to use.

image

and how it will start. Now for testing purposes, I normally will have Manual as well as Item Created, but will clean that up before Production.

image

finally you get a solution where you get to design your workflow. I think there are enough call outs in the diagram so that you can get the picture 🙂

image

Next you get a few Workflow Activity items from the toolbox to design out your Workflow as below

image

We configure the task option either in the Project Properties window or you can click the configure link in he design surface and configure the options as you see me do below. Now in production you can certainly do business logic for alot of these options which as you see involve C# code that gets translated to XAML when you deploy your project

image

Here are a few more edits made to the project, things that you will see in the Outcome when testing. I am including the Logging as a mans to show you that there is nothing up my sleeves as well as it is good practice to document your workflow and give feedback to the End User/ Workflow Actor. The Logging below will show up in the Workflow History chronology.

image

A couple of things to call out here. You notice the “if” section and below it it has the “outcome_0 == 0” so basically, when you use a Task Activity the tooling will create for you a Variable called “outcome_0” and based on the disposition of the Task, it will be either Zero(0) or One(1) to denote the outcome. Zero means it is a Successful Approval.

image

Above again you will notice the UpdateItem Activity. I am saying here that if the Outcome is a successful Approval I want the Workflow to go ahead and Update the Field “FinalAdjudicationOutcome” to the choice field option you see above. I have the inverse of that applied on the Else side of the Conditional Check.

 

Below is just another logging to show you when the Workflow ends.

 

image

 

So when you are done, the resulting solution may look like the below

image

Now you remember when i said that you need to note the name of the List Instance, here is where you will use the name; you see, you want the App to begin on the List Instance you created and modify the Start Page setting

 

image

Once that is done, you go ahead and Deploy your solution to your site. The URL below shows the FQDN of the location where the App will be. This reflects the On Prem solution. As you know if you read the Precis, I think my App Model installation is busted which I found out in testing. So we are going to copy my solution to a Cloud SharePoint Instance I have.

A benefit to you the Reader

Now, this is indeed unexpected but it does show you that your Visual Studio Solution

A. Can be used on a Desktop WITHOUT SharePoint being installed AS LONG AS you are pointing to a Cloud Instance of SharePoint. Obviously, you are also not doing a Farm Solution

B. Your solution is Portable, you can move the same code between On Prem and in the Cloud as long again as it is NOT a farm solution

C. You can create a Development Environment in the Cloud, Azure Perhaps and kill it when you are done, no need to install VM’s to do SharePoint work anymore, with the same qualifiers as above

Now Deploy your solution and if you are successful you will see the below.

 

image

Testing in my On PREM environment

Once you examine the site by clicking on the URL, you can see the results of your Assets deployed inside your List Instance

image

Next create a Item and fill out the Metadata fields

image

Here is where Testing Failed and I copied my code into a NEW VISUAL STUDIO PROJECT targeted at an Office 365 SharePoint Online Tennant

My New Visual Studio Project targeting SharePoint Online

So, I added a new Project to my Visual Studio Solution, see the callouts below

image

Deploying it gave success as well, see below. This time the URL targets my Office 365 SharePoint Online Instance.

image

Testing

The testing below occurs in Office 365 SharePoint Online after re-deploying our App targeting this environment.

 

Testing our Visual Studio Solution in Office 365 SharePoint Online

Now we will test again, this time in Office 365 SharePoint Online. Again we fill out the necessary Metadata fields.

image

This time we have our Workflow Starting as we can see bwlow

image

and you can see in the Workflow Status that we are set to go and the Workflow is working

image

next we adjudicate the Task Assigned

image

and our result is

image

Trust but Verify

Now, indeed, I had a few other steps in my SharePoint Designer 2013 version of this, using Stages, and we can certainly duplicate this in Visual Studio, but this blog post was long enough, and the simple truth is that you basically repeat the steps I have above and the Designer is built to show the FLOW that the workflow will take, so its “monkey with a wrench” work, the examples in this blog post shows you how to do it once, you now take that knowledge and repeat it as much as you need for a holistic solution.

Back to our workflow at hand. If you recall, if the person approved the Item, the Workflow should Update the List Item by changing the field of the “FinalAdjudicationOutcome” to what you see below, which it did. Furthermore, the images in the Testing Section shows some of the Logging we did so you can infer the path that it is taking.

 

image

Summary

So in the end, we still have our solution, our blog, and WE both learned a few things in this process. Have fun y’all. Irie.

May 25, 2013 Posted by | Content Types, Office 365, SharePoint 2013, SharePoint 2013 Workflows, SharePoint How-To, SharePoint Online, Site Columns, Visual Studio 2012, Workflows | | 19 Comments

Addenda to Finally a SharePoint Designer every BA and Dev will Love

Alas, it was getting a bit busy on the blog post to cram so much Information so this Post follows on the 2 that were already done.

  1. Part 1 – Stages, Steps, Loops, and Visio Professional 2013
  2. Part 2 – Put it all together with HTTP Service Calls via REST and the Dictionary Object/ Variable

This post will look specifically at making those REST API Calls in SharePoint Designer 2013 (SPD2013) on Web Sites “other” than SharePoint i.e. those FREE API’s that are out there. This one will use the Free Weather Online API. You can get an account here and get a Key Just for you 🙂

So..What’s our Story

Well we will endeavor to create a Site Workflow that will run every 24 hours and 5 minutes and display using a Promoted List in SharePoint 2013 the Weather Forecast for the specific Office Location in our Fictitious company. Now, I’ve done a presentation at a SharePoint Saturday or two that discussed creating a Custom Action that would take a parameter (text box field) holding Zip Code so one could customize/personalize this Workflow.

We begin by creating a new Site Workflow

As all good post go, we tell you how to start, so Fire up your SharePoint Designer 2013 and connect to your SharePoint 2013 site, this can be On Prem or in Da Cloud. Click on Workflow then New Site Workflow

SNAGHTML1ffc4d8b

Next you Stub out your Workflow, this time you should know all of my bag of tricks now to make life easier so I am including as much as possible here below, if you don’t know or haven’t been following the series, take a look at the other two links in the top of this post.

image

I now do my magic for the HTTP Call, get the Sub-Set of Data I need and then Iterate through the values

 

SNAGHTML201d158b

Above is the Fiddler Call I use to inspect my results so I know what to put in my SPD2013 Get Item From Dictionary Action, once you have that bit of information, then the rest, you have seen be do before. So…

image

Basically we make our HTTP call, put it in our data Sub-Set, and Get each individual element inside our loop, the ONLY thing different in this example is that I am doing a Create List inside the loop to add the current record to my Promoted Link List and you will see that later on below.

image

Once you invoke the workflow it does its job and remains in a Paused state for 24 hours and 5 minutes then runs again. To the user they will see below if all goes well when they view the list or we can have it as a Web Part or App on a page

image

Summary

So there you go, you are now knighted as SPD2013 Workflow professionals, go thee forth and conquer!

So, my good buddy Chris @givenscj Givens, a really brilliant fellow said that doing this series in Visual Studio would be a benefit. I will take a few days to do that, but I promise I will, need to go back to billable work now 🙂

 

April 30, 2013 Posted by | REST, SharePoint 2013, SharePoint Designer 2013, SharePoint How-To | , , | Leave a comment

Part 2 of Finally a SharePoint Designer that Developer and BAs will Love

Purpose of this Blog Post & Primer for this Post

This post follows up on a previous post below where we discussed Workflows in SharePoint 2013 through the eyes of SharePoint Designer 2013 and Visio Professional 2013. Part 1 is linked below, this is Part 2

Part 1 – Stages, Steps, Loops, and Visio Professional 2013

In the above post (this one) I will go about showing you the tooling and various simplistic but apropos examples designed solely to drive the usage home, in Part 2 we will use everything in a practical REAL WORLD sense

Part 2 – Put it all together with HTTP Service Calls via REST and the Dictionary Object/ Variable

In this post I will take a Publicly Available REST API probably the Weather API or Twitter API and use the HTTP Web Request along with the Dictionary Variable in SPD 2013 to surface it in a SharePoint Promoted Links App (List)

What is the Dictionary Object/ Variable

Simply put a Dictionary Variable is an Array i.e. a collection of related items that is indexed/indexable but in more detail it is a container designed to hold a collection of other variables which can be of a different data types. Specifically we have the following actions out of Dictionary

  • Build Dictionary
  • Count Items in a Dictionary
  • Get an Item from a Dictionary

image

Now before we get too deep into The Dictionary Variable/Object, lets take each of these actions one at a time in a simple scheme and see what they do exactly; kick the tires so to speak, in our real world example we will NOT be creating the Dictionary Object as much as consuming JSON data and dumping the JSON data inside a dictionary object. You get it right? JSON data usually comes across as a JSON Array or JSON object, in our case we want that JSON array, even if it is one item, the Dictionary Object/Variable EXPECTS to see an array, I actually wrote a blog post https://fabiangwilliams.wordpress.com/2012/12/31/limitations-when-using-sharepoint-2013-workflows-to-return-json-data/ explaining that issue, which i think is a BUG that should be handled by the SharePoint Team.  But lets leave that on one side for the moment and get back into our intended post.

It is ALL explained Here

As mentioned earlier, a Dictionary Object may be considered a collection of related items. Now to drive this point home lets use what we have at our disposal, in fact we will use two (2) examples, the first of which is to simply build on what we did in Part 1 using the Bank of Fabian Example.  You see, there are ALOT of post out there that do a good job of explaining to you how to get Weather Data, Twitter Data, ITunes Data, you know all the public REST JSON available stuff, and granted I will do one here as well in example number two in the spirit of being complete. However, what you don’t often see is showing how to use SharePoint own REST OData examples, so I will do one here. Lets set it up for you.

Our Use Case

Now I’m a big believer in Use/Business cases when doing Demos’ and not doing parlor tricks for the sake of “Hey! Look at this cool new stuff I can do”, so The idea here is that

1. You can consume data from ANY SharePoint List as long as you have an account that has permission or an App that does, and then act on or manipulate data from inside your Site Collection [assuming a Site Workflow here]

2. You want to expose data/information to an audience that doesn’t have access to certain data or hosted elsewhere

Web Site:  http://adotob.sharepoint.com (this is my Office 365 Dev Site)
List Instance: https://adotob.sharepoint.com/_layouts/15/start.aspx#/Bank%20of%20Fabian

image

So from the above we can tell that we have a list called …/bank%20of%20fabian and it has currently 5 items inside it yes? Ok, good. Now in order for us to get to that data we can call on our SharePoint oData service located here

https://adotob.sharepoint.com/_api/web/lists/getbytitle(‘Bank%20of%20Fabian’)/items

Now you should understand that SharePoint 2013 REST APS doesn’t understand the $json options so, it will render its result in XML, however there are quite a few tools out there that can convert your XML to JSON. In fact if you adjust your request header on your call yourself in Fiddler or in browser extension such as Chrome or FireFox, you can get the visual effect you are looking for as well.  So lets see what happens when you click on the link here for the REST API call

image

Now that is NOT going to be useful to us, so I will use this Chrome extension called ChangeHTTPRequest and after putting in my header i need which is

Accept: application/json;odata=verbose

I get the below

image

Now admittedly that is also difficult to read, so you should invest in the FREE JSON Viewer I always use and its Waaayyy cleaner, just cut and past the entire content and you can see what I mean.

image

So now that we have established some “Trust but Verify” credibility, next lets look at what we need to do in SharePoint Designer 2013 (SPD2013) to move this forward. We will be Demonstrating the following Capabilities in this Example

  1. How to use Dictionary Variable/Object
    1. We will build a Dictionary Variable to hold our HTTP Header information so we can get JSON Data
    2. We will Count Items in a Dictionary Variable so we can get the “Count” value of all items in there to assist us in our “Loop” that we may iterate through all the items in the Dictionary
    3. Get Items from the Dictionary that we may use to (as in our case) Write to the Log History so we can see what we are consuming, but in our Part 2 Example coming up using PUBLIC REST JSON data we will use that data to load into a ListItem
  2. Call a HTTP Web Service
    1. We will call that webservice we discussed above to get oData back
    2. We will discuss the other Dictionary Variables we will need in Support of this Call such as our ResponseContent and our subset of Data we want to inspect
  3. Do a Loop
    1. We will use the total items count that we got from our “Count Items in a Dictionary” Action as our loop counter max value in our Loop construct

Lets Build out our Workflow

The first thing we will do is create a Site Workflow

SNAGHTML1c311bfc

So in keeping with “Fabian’s Best Better Practice” we will stub out our Stages and Get some basic Logic out of the way

image

Once that is done the first thing we will do is build a Dictionary Variable to hold two items we need in order to get JSON data to be returned; we need to set the Accept and Content-Type HTTP header so the browser knows what we expect. We click Action then under Core Actions you will find Build Dictionary, because I use it a lot it is in my Recent Actions also

image

Once you click on ‘Build Dictionary’ you will get…

image

1 – You will then click on ‘this’ which will open up the dialog in [2] and in turn you will click the Add button. In doing so you will enter two Variables into this Dictionary Variable of String Data Type as aforementioned, in [3] I am showing you how i do it for the Accept header attribute.

image

When you are done, click the Ok Button. AND NOW YOU HAVE SEEN HOW TO CREATE A DICTIONARY VARIABLE and an acceptable use of it.

Next we will “Call the HTTP Service” by again clicking Actions in the Ribbon and then…

image

So again by clicking [1] ‘this’ we get the dialog box to enter the information about our HTTP REST Service which in this case we click on the ellipse [2] and put our workflow variable we created earlier that holds our URI, then we click [3] the OK Button.

Oh… i forgot something, but we can do that now… so you see in the above figure the second line has the (Output to Variable:dictionary) right? so I like to tidy up my Variable name, so what I do is click on the word ‘dictionary’[1] and create a NEW variable called RequestHeaders [2]

image

Now that that is done, we want to further configure the Service Request Call so we will ‘Right Click’ on our ‘Call’ and then Click on Properties..

image

Then I want to set the “RequestHeaders” Property to my Dictionary Variable “RequestHeaders”

image

and then click the OK Button.

Next we will need to ALSO create another Dictionary Variable to actually HOLD the data that’s coming back, if I haven’t said it before, that data comes back in the form of a JSON Array and the Dictionary Variable is the only object suitable to accept that data. So

image

and we name it ‘JSONResults’ so if we inspect the properties again you will see that we have everything we need now to call out to our HTTP Service and get meaningful results back

image

So now we can actually got GET the DATA now, by using yet another Action in the SPD2013 Ribbon, this time its the ‘Get Item from Dictionary’ Action

image

Once we do that we will want to click the ‘item by name or path’ link and give it the SUBSET or WHOLE path to the data we inspected in our JSON Viewer or whatever tooling you have to determine what you need. In our case we want the “d/results” subset then we will use the Index variable to get each line item. Furthermore we will want to store this information AS WELL into another Dictionary Variable.

SNAGHTML1c5cf00d

So in [1] you have me setting the path based on what i want from evidence in the JSON Viewer, then in [2] I am showing you the relationship of use getting the values from the HTTP Call made earlier and finally [3] I’m dumping that data into another Dictionary Object.

SNAGHTML1c5eb07e

if you forgot here is what i need to build that path take a look above at [1], then [2] to get my Array. In [3] I will use that below using the Index Variable inside a Loop Construct.

So that brings us to the last unique item we will be doing in our Dictionary Item and that is to get a COUNT of all the items in the Dictionary We Need. So again we go to the SPD2013 ribbon

SNAGHTML1c6355f1

and we now need to tell the action which Dictionary Item to count, REMEMBER we want the one that we did the Subset of, not the one returned from the Service Call.

SNAGHTML1c65a1a0

Above [1] we are referencing our Subset Data and we are creating a new Variable of Integer type [2] to put that Number in. NOW this is an important distinction as well because what we have here is our UPPERBOUND number in the Array for out Loop Counter 🙂 smart huh LOL

Next we will enter the Stage “Loop and Write out our Data we Need” and put a Conditional Loop inside there that will use the Index value of 0 to start and STOP when we have reached the UPPERBOUND value of items in the array

image

Now when that’s all done, WE are done, one more Screen Shot and some guidance and you can take a mental break..

image

Now admittedly its a bit busy, and yes, its been hours now since I started on this blog and fatigue is setting in 🙂 but I think i can capture everything I need to say here, and I will wrap up as usual with a video. So we are setting the Initialize and Upper bound of our Loop counter in [1] and [2] respectively. In [3] we are actually going to WRITE OUT TO THE LOG the information garnered from the above two lines and the remainder is the Loop Counter which you saw in Part 1, so now time for the video of it all.

So this blog post is long enough, what I will do for the External Data Call is do it in another Post and I will Link to it here. Hope you learned something new.

Cheers

Up Next – Addendum to Part 2 showing an External HTTP Service Call using REST/JSON [Hyperlink forthcoming]

April 29, 2013 Posted by | JSON, SharePoint 2013, SharePoint Designer 2013, SharePoint How-To, Webcast | , | 3 Comments

Finally a SharePoint Designer that Developers and BAs will Love

We hit the FiveFecta with Workflows

Our horse came in, that is SharePoint Designer has given us Five winning items in this iteration of the product, our five items are

  1. Stages
  2. Loops
  3. Steps
  4. Dictionary Object/Variable
  5. HTTP Service Calls

With all this you have the means to create atomic unit of work, conditional statements as well as the ability to make external calls to REST-full Service returning JSON data. The last piece of the puzzle is the addition of Visio Professional 2013 and the Stencils it brings to both author and report on the activities of the Workflow Activities.

Purpose of this Blog Post & Primer for this Post

This post well explore various usage scenarios of our Five Fecta through commentary, discussions and demo/screen shots. I am considering breaking this up into sections but perhaps it will just be one big post that covers a single solution, I’m still toying with the idea, either way its genesis is still fluid. If indeed i do break these up, I will put the various parts in this section.

Part 1 – Stages, Steps, Loops, and Visio Professional 2013

In the above post (this one) I will go about showing you the tooling and various simplistic but apropos examples designed solely to drive the usage home, in Part 2 we will use everything in a practical REAL WORLD sense

Part 2 – Put it all together with HTTP Service Calls via REST and the Dictionary Object/ Variable

In the above post I will take a Publicly Available REST API probably the Weather API or Twitter API and use the HTTP Web Request along with the Dictionary Variable in SPD 2013 to surface it in a SharePoint Promoted Links App (List)

What’s new with Workflows

Some things that you must know about Workflows in SharePoint 2013 is that unlike SharePoint 2010 that was built on the platform of Windows Workflow Foundations 3.0 (WWF3) this version of SharePoint is built on Windows Workflow Foundation 4.0 (WWF4) and .NET Framework 4.5, it also employs a new Installer/Manager called Workflow Manager 1.0.  Now you have the ability to design and create complete declarative workflows, REST and Service Bus messaging. You should also be aware that the SharePoint 2013 features and capabilities only comes available to you and your tooling after you download and install the Workflow Manger 1.0 Service and configure it to communicate with your Site Collection. For more on the Workflow Manager 1.0 please see Start: Set up and configure SharePoint 2013 Workflow Manager Finally with Visio Professional 2013 add-in provides you with a Visual Workflow Development experience both inside SPD2013 and outside inside Visio Professional 2013.

<RANT>The one thing that I have as a gripe (but I totally understand why) is that Reusable Workflows are GONE in SharePoint 2013 Workflows </RANT>

But that is somewhat disingenuous because while you certainly cannot do it in SharePoint Designer 2013 if you create your workflow in Visual Studio 2013 and make a reference to the Workflow Manager 1.0 you can attach to the GUID of the Content Type.

This is what I mean, open up SPD2013 and fire up a Reusable Workflow and you will notice that you cannot bind a Content Type that you are used to doing in SPD2010 to this Workflow

image

but if you change the platform to SharePoint 2010 Workflow as seen below you can change the Content Type and make a selection to bind it accordingly.

image

But lets get back on track.

Stages – What is it, Why do we need it, What Problem does it Solve

Stages are new and introduced into SharePoint Designer 2013 (SPD2013), a stage can accommodate any number of shapes inside Visio and Action/Activities inside SPD2013.  There has to be at least one (1) stage in every SharePoint 2013 Workflow and there can only be one path in and one path out of a stage, although while inside the stage they may branch. I will provide a demonstration of that below through a parallel process. You may NOT nest stages, if you want to have nesting capability, you should use a “Step” within a “Stage” in fact it is quite neater for others to follow even from a design standpoint. As you exit a stage, you select what other stage it will transition to, and within that transition step you may also employ conditional logic to determine what path it should take as it exits the current stage. Upon completion of a workflow you should set the transition to End Workflow. Below are some examples of what I just mentioned

Stub out your Stages as a Best Practice

Now as a Object Orientated Developer that is used to Modeling/Prototyping my Classes/Modules, it is just natural for me to see ‘Stages’ in that same fashion, I first consider the ‘Start’ OR ‘End’ of what i need to do and either work forwards or backwards thinking about all the pieces that will make the effort succeed, in the same vein, when I am building a SharePoint Designer 2013 Workflow I pause to consider what my Stages will be, and HOW I will transition between them, that way once I get that thought process out of the way, I am free to just put the logic I need inside my stages and my work becomes so much easier, or at the very least, I have a plan of action that anyone can follow. One more secret about doing it that way is that I can do a Visual Layout of my Stages and take that to a Business Analyst (BA) or Business Decision Maker (BDM) and validate what I am intending to build.

Step 1: Create a Workflow (in this example I am doing a List Workflow)

SNAGHTML7544272

Once you fill out the necessary fields and click OK, you will be taken into the Active Workflow Design pane, and a Stage will already be present and waiting for your actions.

SNAGHTML959168

As denoted in callout 1, we have a default stage created for us, it is called “Stage 1”, but obviously you should change that to something more meaningful, in fact, the names of Stages are by default going to be the Status Messages that you see when your workflow is Running under the Status field in the Document Library or List, so you should think carefully about how you define and layout your stages as well as the nomenclature.  This is yet another reason why I elect to stub out my Stages before anything else.

In callout 2, you will see the transition to stage area where you can direct the flow of the workflow, as previously mentioned but worth calling out here:

  • there is one way into a stage and one way out
  • you may directly tell the stage to progressively move to another stage, or use conditional statements to drive it dynamically or End the Workflow in that area

In callout 3, you will notice Stage is grayed out, but that is because at the point of me taking the screen shot, i was in the active stage and as i mentioned before you cannot NEST stages inside stages therefore the option to create another stage was not provided.

Once you have stubbed out your Stages as I have done below, you will have something similar to what is below, notice I am showing you what a Stage Transition looks like as well as showing you in the “Wrap Up” stage, that the workflow will terminate there.

image

If we check out our document library we will treat it as a Bank of sorts. We will use a Document Library because it represents a slip of paper that will authorize a transaction, a Credit or Debit, so for instance

image

We have a Metadata Column that will hold current balance after a Credit or Debit transaction is applied. Coming back to SPD2013 now we have to set up variables to hold these values in order to do our mathematical computations ergo

image

Looking at Basic and Conditional Stage Transition

Now that we have Variables in place and mind you, we could have just read from the Metadata columns, but I prefer to create variables so i have an assurance of the Data Type I need to use, we will now create some logic to demonstrate how we can transition through stages. I will not go into much detail here because the idea of this exercise is to demonstrate some of the ways you can transition through stages. In the first one we will just move to a different stage, whereas in the second, we will be checking for a condition

image

In the above figure “1” and “3” are basically logic to take some action or capture some variables from the Current Item, your focus here is Stage Transitions. Notice in “2” we are simply just calling the Stage we need to go to, In “4 ‘we are checking to see first (a) what type of transaction this is, if it is a Debit, then.. does the individual have enough money to do what he/she wants to do, it he/she doesn’t then go to the Stage “IF Crap Hits the Fan” otherwise, if the criteria is met or this is a Credit Transaction, go to “Process Calculation” Stage.

Looking at Internal Mechanics of Stages

So, lets take a look at what can happen inside Stages, for this example we will just look at Parallel Blocks and additional Conditional Logic

image

So what we have in the above is an example of a Branch in a Stage, we accomplish this by having a Parallel Block [1] and we have two steps inside that block [2] which will be run in parallel. You will see proof of that via the Visio Diagram and in the Workflow History Log, and you will notice that what is inside each Step runs in ‘Sequence’ [3]

Next we will look at how we “Process Calculation” and “Wrap Up” Stages

image

In the above illustration you will see that we are not doing anything special here that we haven’t done before, we are using conditional logic in both the stage and transition step to determine the path. you will also notice I make heavy use of the Log to History action, I do this to simplify my working area but these steps can be other stages or other actions, for me I am using it to convey messages to you about what is going on.

Below are some examples of what you would expect to see under differing scenarios

Scenario 1 – Add Money to The Account

image

We will look at the ‘You got Paid’ ledger under the Workflow History

image

Above you can see that in the log that the current balance was $30, but after crediting $100 it is $130 from the prior image showing the Document Library. Now lets look at a Debit.

image

Now lets take out more money that they can handle and see what happens in the video below pay attention to the last entry.

 

Summary on Stages

Hopefully the images and video demonstrates some of what is possible when using Stages in SharePoint Designer for SharePoint 2013 Workflows. If I didn’t already say it, its worth emphasizing that Stage Names become the Status Fields by default in your Library or List being acted upon, but you can also set your own Workflow Status Message.

A more meaningful Look at Steps

So, in the example of Bank of Fabian doing Debits and Credits, you saw “Steps” being used within a Parallel Block, but I want to build on that, and show how steps can really organize your Workflow. In this scenario lets take the approach of “Opening a Bank Account” so we will need to

  1. Run persons Credit
  2. Check Source of Initial Funding for Opening of Bank Account
  3. Run them through ChexSystems
  4. Verify them against Government Regulatory Checks
  5. Do a Approval Process for Opening of Account
  6. Open the Account if they Pass all the Above, Reject if they Don’t

Now off the bat, some of these steps can be done in Parallel; I would say steps 1 through 4 can be done all at once, then we do 5 and then 6, lets look at that

Stubbed out this is what it looks like

image

Now if we add just a little bit of logic in there it could potentially shape up to be like the below

image

What does Visio Professional 2013 Bring to the Table

So, thus far we have looked at:

  • Stages
    • Internal Mechanics
    • Transitions
    • Conditional Statements Within
    • Branching
  • Steps
    • Overall Organization
  • Loops
    • Placement and Usage

Its ample time we look at how this effort looks like Visually in Visio Professional 2013, I cannot overstate how much this is important

to both TDMs, BDMs, and the Developer/Architect. Now you can approach the problem from either end. In one hand you can have a BA or End User mock up a Visio Diagram of what the process should be like and give that to the Dev/Architect, on another hand like I do, i often will stop after I stub out the process and put in the transitions and ASK the BDM’s .. “Is this what you want?” inside the Visio Diagram which is a lot friendlier than SharePoint Designer Text Based Viewer. So based on our examples above lets move forward.

Example 1 – Bank of Fabian

image

What you have above is the complete process flow of the Workflow in Visio Stencil, now lets dissect it.

Stages Breakdown

image

 

image

image

In the above you can see how Visio represents the shapes for SharePoint 2013 Workflows and ANYONE can do this, the stencil legend is below

image

The above represented the Visual Designer View which is all well and good, but there is even a simpler view that you can see that is called the Stage Outline view and that i believe you can take to anyone and they can really understand at a 10000 feet view what is going on, and you as the Developer / Architect can have some assurance you are on the right path.

image

End of Part 1 Summary

I am actually glad that I have broken this out, because it truly is a lot of content.  It is my hope that the above illustrations, video and explanation will help you understand that it is a Brave New World out there for SharePoint Designer 2013 and this is just the scraps of it, Chicken feed, in PART 2 of this Blog, I will use what we have here and really open your eyes up on how you can make a ROBUST process engine that can make External Calls, be “State Machine – esque” and totally be NO CODE where before you certainly had to use CODE or a Third Party Product.

 

Stay Tuned…

April 24, 2013 Posted by | REST, SharePoint 2013, SharePoint Designer 2013 | , , , , , , | 15 Comments

Limitations when using SharePoint 2013 Workflows to return JSON data

Précis

I struggled with the title for this blog; dare i say, after spending almost two days trying to make SharePoint Designer 2013 and Visual Studio 2012 Workflow return data from a few notable providers [YouTube, Twitter, iTunes] using the Dynamic Value / Dictionary Data Type in JSON format, and not being able to as documented, i was frustrated to say the least. I would have been Ok, if it wasnt for the fact that the same exact Logic/Process works for other providers such as [FreeWeatherOnline, etc] returning data in JSON format, the key difference being the structure of the JSON data being returned.

This is for a few SharePoint Community Events that I have been scheduled to present this material. So after beating my head against the wall, sending out S.O.S tweets, and pinging a few folks that are versed on the topic, I ended up doing my Demos with the REST API provider that returns the JSON data in the way that works OOB and documented in both SharePoint Designer 2013 (SPD2013) and Visual Studio 2012 (VS2012). Nevertheless, this was going to haunt me if i cant get it to work, so i went back at it and with the help of Bart @bart_tubalinal Tubalinal who is the self professed and "fabian validated" Pound for Pound Undisputed Developer in the World, we proved out that if you altered the return JSON data from the providers that didn’t work as expected, and then make a call from SPD2013 and VS2012 using the DynamicType / Dictionary variable, it worked as expected.

I will describe the process we used to determine this below…

Background Research

Below, I will show you three data calls to REST API providers returning in JSON format, showing you both in the browser and in the JSON viewer, I call your attention especially to the JSON viewer and the hierarchy.

Screen clipping: Google YouTube API Above

Screen clipping: FreeWeatherOnline API Above

Screen clipping:  Twitter API Above

Screen clipping: YouTube JSON Data Returned Above

Screen clipping:  FreeWeatherOnline JSON Data Returned Above

Screen clipping:  Twitter JSON Data Returned Above

Hypothesis

What we found out is that if you have anything under the Root of the JSON node other than a JSON Array, for example as in the case of a few, the Version Number [returned as a JSON Object], although it works perfectly in a browser, or JSON Viewer, or Fiddler, it doesn’t make the right call when using SPD2013 or VS2012. If after modifying the data output and removing anything that is NOT a JSON Array from the Root of the Node, it should work as expected.

The first thing to prove it out is to have SPD2013 or VS2012 make a call to a URI that returns JSON, so that can easily be accomplished via Visual Studio Project to create a new Site, and then drop a file with the removing anything in the root that is not a JSON Array (Collection) and calling that Web Site from inside for example SPD2013 then it should return the requisite data than can be consumed by the Dictionary Object.

Test/Prove Out

To begin, the first thing we need to do is remove the "appVersion: 2.1" JSON object out of the data returned, below is what is looks like without any adjustment

after you remove it, the raw file looks like below

just to verify, ill put it into a JSON Viewer to make sure it is what i want

then drop that raw file into a text document and place it at the root of the newly created Visual Studio Project Web Site

verify that you can get to it from a browser call

Analysis

Now, below I will show you WITHOUT adjustment how the FreeWeatherService REST API works right off the bat, you will recall above that the only thing at the JSON root node is the JSON Array. So we put it into SharePoint Designer as below

Screen clipping: See the URI and Process Above

Screen clipping: Above you’ll notice the return data goes to the Dictionary DataType

So after you publish the Site Workflow and run it on the Site, you get what you expect to see below

Screen clipping: SharePoint Promoted Links List with JSON Data Returned

Showing the YouTube Working with the Mods to the Data Set and Without the Mods

So, below you will see how we make a call to the Virtual ASP Visual Studio Site [look at the URI call line you will see it set to localhost and port number]

Screen clipping: SPD2013 WF with the Modded JSON data call Above

After publishing the Site Workflow to the Promoted Links List we can see the output works as expected.

Screen clipping:  Promoted Links List showing the Top 10 YouTube Videos displayed with Modded JSON data Call

Now Showing it NOT working as Expected

Below you will see the same code as in the one that worked, except the URI is set to the Google YouTube REST API and no Mods will be done to this data set.

Screen clipping: Above the same Logic/ Process except this call is made directly to the YouTube REST API

Now pay attention to the logging above, you will see that when the Workflows is published and deployed and ran, that the line for the call fails.

Screen clipping:  Above is me executing the Site Workflow

Below you will see the Workflow status showing that the process halted

Screen clipping:  The Workflow Status showing it didnt work

Report

So, I originally called this a BUG, but for now it is just an observation. Ill be happy to know from our community folks, MVPs, MCMs, and other folks that come across this blog your thoughts. Sadly, I have turned off comments on my blog, but you can always shoot me a tweet at @fabianwilliams

thanks cheers.

Other Notables but I wont write it up, you can discern yourself

See me making it work in a Custom Action and also Not working using one REST API result that is in the format I said will work, and the other with it not.

Screen clipping taken: 12/31/2012 3:32 PM

Screen clipping taken: 12/31/2012 3:32 PM

Screen clipping taken: 12/31/2012 3:34 PM

December 31, 2012 Posted by | JSON, REST, SharePoint 2013, SharePoint Designer 2013 | , , , | 1 Comment