How to reuse a workflow which contains string with place holders?

Hi All

I have an workflow where i am sending an email using smtp. I am using html template for the mail body. So first it reads an html file and stores the same in a string variable. The string contains place holders which dynamically takes variables values. Then i pass the string into the mail body.

So here as we are using variables for place holders, can this whole workflow be made to be reused using invoke workflow or custom library ? I doubt because the place holders and variables will be changing for different requirements at different times.

Please suggest if it can be reused by making any changes ?

setup the placeholders like e.g <PersonName>
pass a dictionary or Key-Value-Column Structure Datatable by the in Argument

it alllows to setup an iteration over the dict/datatable and the replacement of the placeholders can be done dynamicly

e.g For each row

1 Like

No, the place holders and variables orders are not constant. So that can not be done.

as the template text can passed as input argument as well or be readin by a txt file it can be done dynamicly and we have practiced also in the past as well

As you can see the String.Format contains the template string and the variables for the place holders. Those variables will change for other workflows in different orders. So how can that be made generic ?

when you are running with the format then its maybe inflexible
but when using the text approach then it should work

@kkpatel Instead of a String.Format, I think it might be possible to use a Replace method to Replace a Key PlaceHolder with an Value with a For Each as Suggested by ppr. Provided you Store the Placeholders Separately.

Also change in the Placeholders mean that you need to change the Template as well. So in this way I think it is possible to make it as a Re-usable Workflow.

But as for different workflows the number of variables passed and the order in which it is passed will change, so how to handle those things is my big question.

Hi All

Is there any other way it can be achieved ? The main issue here is the mail body needs some variables which are not definite.

@kkpatel So the variables are not definite. So that would mean there would be as many arguments as the values that need to be passed, In that case can’t we make the argument as an Array of String, In that way. It can have 1 ,2 or as many values as you need.

Thanks @supermanPunch! I will try…

1 Like

Yes @supermanPunch, Its working. But next thing is to form the array it has the dependency with the email its going to send. Accordingly we need to form that array of strings in the same order as the place holders occur inside the html file. So if tomorrow the html template changes and the place holders position got changed then we need to make changes in the array in the code. So again no point.

@kkpatel Yes, But however Since the Developer is developing the code, the Template File Placeholder Order and the Order in which you pass the variables will be determined by the Developer. So it may be a useful approach in one way.

Ofcourse !!! But my aim is to make it generic reusable component. And the Html body and place holders we are using so that we can make changes without modifying the code. But any way it is creating dependency. So not sure if it can be made reusable or not but your approach will definitely help up to some extent.

1 Like