1

We have a list workflow that sends email notifications to different users and admins depending upon the stage and type of service request. The body text of the notification email is different for each kind of user or admin and each kind of content and includes different pieces of information from the current list item.

Additionally the contents of the emails change frequently. So I didn't want to have all the email "templates" stored inside the workflow. Not everyone on our team has access to SPD, nor the skills to open a workflow, make a change to a variable, and publish it successfully.

My idea was to set up another list of the templates with each list item marked for which type of request and which stage. This way many of our admins could go in and update the templates as needed.

So I set that up and have the workflow is pulling up the correct template. But now I want to mix in the information from the current item.

For example, if the body text was in the work flow it would look something like this in the string builder if the template text was assigned to a workflow variable:

Hello [%Current Item:Created By%]

We have received your request for [%Current Item:Title%]. It will be processed in the next 24 hours.

With the [%Current Item:Created By%] and [%Current Item:Title%] having been added with the Add or Change Lookup button.

But I want to pass a string from a list item. How can I indicate that there is a look up in those places? I tried typing what the string builder would show, but of course that didn't work, because the look ups are more than just some text.

Basically I want to do a mail merge. Is there a way to do this?

Is there some different way to keep the text for emails out of SharePoint Designer?

Edit

I was going to try some string handling so I create a variable in the workflow and added some [%Current Item:Created By%] (typed, not inserted with the Add or Change Lookup button. I get an error message

Using the special characters '[%%]' or '[%xxx%] in any string, or using the special character '{' in a string that also contains a workflow lookup, may corrupt the string and cause an unexpected result when the workflow runs. So that is interesting....

  • Right, you want a plain-text token. steer clear of the brackets and parenthesis. – ghangas Aug 18 '17 at 19:12
2

Yes, there is a way to do this. https://dev.office.com/sharepoint/docs/general-development/working-with-web-services-in-sharepoint-workflows-using-sharepoint-designer gives you enough information to get started, but you could get the same by googling 'http web service in SharePoint workflows'. Depending on your requirements you could store the data you want to query in any SharePoint list.

Then write your workflow to stringbuild from the returned data. For example, you might always use Hello [%Current Item:Created By%] but then append the returned text of a SP webservice query for the rest. Alternatively you could store the entire text of the email in SP list then replace your tokens in the workflow:

Once you have the results back from the web service call I would extract the email text from the dictionary into a string variable. Like this: borrowed from https://dev.office.com/sharepoint/docs/general-development/working-with-web-services-in-sharepoint-workflows-using-sharepoint-designer enter image description here

Grab the Created by field like this and stick it in a workflow variable: Created By into WF Variable

In this image I have left that out to show the salient replacing bit.

Use replace function

Then you can use the replace function in your workflow to replace the token "nnnnaaaammmmeeee" with the string Item-Name.

Optional variant is to find a substring in a string put it in a workflow variable and the use the extract a string from start, and extract a string from index (use calc to add the length of your token to the index)

2 warnings:

  1. Web service calls in workflows are not light and easy. They take effort and massaging, and be sure to watch your headers because it can be fiendishly difficult to parse the results if you are expecting xml and get json.
  2. In this method you make it so that the text can be maintained by nearly anyone, and it is simple. However, even with documentation it might be too complex to maintain when you get promoted. Be careful to not make something so complicated you cannot take the promotion.
  • I've already got the webservice rest calls to get the string templates. I'm trying to figure out how to replace the tokens with the information from the current item. Can you explain the left(instr("nnnnnaaammmmmmeee')) + [%Current Item:Created By%]].... part a bit more. – Rothrock Aug 18 '17 at 14:57
  • forgive my pseudocode. I am replacing it with a better explanation. – ghangas Aug 18 '17 at 18:56
  • Ah I actually just needed the Replace part. I already had all the other part done. It is a list workflow so I don't need to do the lookup to get the id. Thanks. – Rothrock Aug 18 '17 at 20:06

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.