0

Business Case: Surveys are sent out for each new KB my team builds and they are live anywhere from 2-4 weeks. The business has requested that each week a survey is live, an email be sent out that contains the total number of responses (so they know if they need further communication).

Problem: I don't want to grant full control to the surveys allowing them to view the # of responses on their own (these surveys are anonymous & restricted view to creator). My idea was to create a workflow that captures that number (via REST API) and sends out the email with it.

Progress: I managed to find the field I need from the response, I built out the workflow but it's failing before the Dictionary is even built.

Dictionary has 1 entry:

  • Name: Accept
  • Type: String
  • Value: application/json;odata=verbose

Here's the URL I'm using for the call:

http://[mydomain]/resource/025/_api/web/lists/getbytitle('[list display name]')/?$select=ItemCount

Here's the properties of the Call: https://goo.gl/photos/mJKTPqzro3AUqbc69

Here's an overview of the workflow including the 'Get...' action: https://goo.gl/photos/W8N83p3TThDPFqYV8

What happens when the workflow is ran on an item it gets stuck 'retrying' saying "…HTTP NotFound…[url to list item]..." then it goes to 'Suspended' with an HTTP 404 error.

Any ideas what I'm doing wrong? Why is it getting stuck building the dictionary?

Thank you in advance for your time & help!

P.S. sorry about the long post, I wanted to avoid a bunch of 'back and forth' to get the details.

0

Glad you offered a long post - helps me narrow down on what I think is the answer for you!

That "/?$select=ItemCount" at the end of your URL is superfluous. If you just query http://[mydomain]/resource/025/_api/web/lists/getbytitle('[list display name]') with the REST API call it will return a dictionary of metadata about the list. Then your Get d/ItemCount will extract that data from the dictionary and give you the variable you need.

Give it a shot and let me know if it worked - good luck!

  • Thank you for the response Brendan! I tried the Call URL w/o the field name at the end & got the same result: it fails at the dictionary creation action. – Kyle S. Feb 3 '16 at 22:03
  • Hmm - Interesting. Here's a screenshot of my working workflow (without the logs): imgur.com/JAbsG7I The only things that come to mind: 1. Make sure your requestHeaders dictionary is correct. It should have two entries, Accept and Content-Type, both strings, and both set exactly to application/json;odata=verbose. 2. You don't have a variable set for responseHeaders. I don't think this is required, but it can't hurt to add a dictionary for those. 3. Maybe some outside chance you have the wrong URL for your site / list name? That would explain the 404 error. http/https, etc? – Brendan W Feb 4 '16 at 0:44
  • While I'm ticking down the obvious stuff - looking at your URL closer, is 025 the name of the site where your list lives? The /_api/web/Lists/GetByTitle('[list display name]') bit should come right after the local site URL. And you kept the '' around the display name but not the [], right? – Brendan W Feb 4 '16 at 0:52
  • OK, so in response to your statements: 1) Dictionary was updated after posting... same issue. 2) I haven't had to set that in the past for retrieving a value... not sure how I'd add a dictionary for that. 3) URL is correct. I can pop it into the browser & get the results page containing the field I'm trying to retrieve. Yes, 025 is the name of the site & No, I am not including the brackets in the URL. Still not sure why it's failing at the point of building the Dictionary (or maybe it's failing at the initiation of the workflow)... – Kyle S. Feb 4 '16 at 20:09
  • Side note: I copied this workflow over to a regular list & it worked perfectly fine [insert confused face] – Kyle S. Feb 4 '16 at 20:10
0

OK, so I never found out why the REST API call wasn't working on the Survey List (I'm guessing it's some kind of limitation for that list type). BUT I did come up with a solution to my problem & business case...

In order to accomplish the task of emailing the # of responses from a survey every week, I realized I couldn't build the workflow on the Survey List itself (didn't want it to run on every response & no way to schedule the workflow to fire every week w/o access to server). I created a list called 'DeployedSurveys' and built my workflow on that list (run on new item). This makes it so the workflow doesn't have to be manually started & so it doesn't run every time a survey response is received. That list allows me to input the Survey Title, Start Date, End Date, URL, & Recipients for each survey I deploy.

The workflow does the following:

STAGE 1

  • Perform the REST API call to get the ItemCount value & store that in a variable

STAGE 2

  • Set 'emailDate' variable to Current Item:StartDate
  • IF statement to check for Current Item:EndDate to be >= Today LOOP

    • Loop through the following while emailDate is <= Current Item:EndDate

      • Send email to recipient group (containing the info you want to send)
      • Log 'Email sent'
      • Add 7 days to emailDate variable and output to same variable
      • Log 'Next email: [%Variable: emailDate%]'
      • Pause until emailDate

        STEP

        • Repeat the REST API call to get updated count/information

    STEP (outside of/after loop)

    • Send email to recipient group (stating this is the last email; include link to results page)
  • ELSE branch (to account for someone setting an End Date that is less than or equal to the Start Date)

    • Log 'Survey is not live'
    • Send email to 'Current Item: Created By' (notifying them of the issue with End Date & advising to restart workflow after correction)

END Workflow

I hope this solution helps someone! It took many hours of work to get to this point... I think the foundation of this (being able to schedule emails that contain hidden list information) could have quite a few applications. Also, if anyone sees something I could have improved on, added, or done differently, please speak up! :-)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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