0

This is the code block that is failing when I call CreateOrUpdateAsync. The Logic App runs just fine in Azure, but when I try to create it using the .NET SDK I get JSON parsing issues.

'foreach': '@variables(""LocationData"")',
            'runAfter': {
                'Initialize_variable_2': [
                    'Succeeded'
                ]
            }

Here is the error message.

{"The template validation failed: 'The template action 'For_each' at line '1' and column '263' is not valid: \"The template language expression 'variables(\"LocationData\")' is not valid: the string character '\"' at position '10' is not expected.\".'."}

If I change to single quote, I get this error.

'foreach': '@variables('LocationData')',
                'runAfter': {
                    'Initialize_variable_2': [
                        'Succeeded'
                    ]
                }

{"After parsing a value an unexpected character was encountered: L. Path 'actions.For_each.foreach', line 651, position 40."}

This JSON formatter & validator doesn't like it either.

https://jsonformatter.curiousconcept.com/

Does anyone know the problem and how to fix it?

Any help is much appreciated! Thanks!

2 Answers 2

1

After reproducing from our end, here is how it was working for us.

"For_each": {
    "foreach": "@variables('location')",
    "runAfter": {
        "Initialize_variable_2": [
            "Succeeded"
        ]
    }
}
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks @SwethaKandikonda-MT! How would I get this to work in a workflow definition file comprised of string? var workflowDefinition = @"{ };
0

I went ahead and created my own Classes to handle the workflow definition.

Here is a sample. It was a lot of code, but it works great.

public class LogicApp
{
    public string schema { get; set; }
    public Actions actions { get; set; }
    public string contentVersion { get; set; }
    public Outputs outputs { get; set; }
    public Triggers triggers { get; set; }
} 

public class Actions
{
    public For_Each For_each { get; set; }
}

public class For_Each
{
    public Actions actions { get; set; }
    public string _foreach { get; set; }
    public Runafter runAfter { get; set; }
    public string type { get; set; }
}

I even wrote Classes to handle my ParseJson Actions. Here is a sample.

public class Parse_JSON
{
    public Inputs inputs { get; set; }
    public Runafter runAfter { get; set; }
    public string type { get; set; }
}

I then called it like so.

var logicApp = new LogicApp
{

}

Finally, I created the workflow definition JSON string. This is an ASP.Net Core app.

var options = new JsonSerializerOptions { WriteIndented = true };
string jsonString = ReplaceFirst(JsonSerializer.Serialize(logicApp, options), "schema", "$schema"));

I used this method to add a $ to the first occurrence of the word schema.

string ReplaceFirst(string text, string search, string replace)
{
       int pos = text.IndexOf(search);
       if (pos < 0)
       {
           return text;
       }
       return text.Substring(0, pos) + replace + text.Substring(pos + search.Length);
 }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.