postorchardcmsorchardcms-1.10

Correct JSON string format for the body request in a WebRequest Activity inside of a Orchard Workflow?


I'm trying to make a POST in a WebRequest Activity, but the body is always empty if I select JSON format:

enter image description here

I have tried escaping and unescaping characters, with and without quotes and spaces, etc:

{\"value\": [{\"@search.action\": \"delete\",\"id\": \"abc-008\"}]}

And

{value:[{@search.action: delete,id: abc-008}]}

But formValues is always empty:

var formValues = activityContext.GetState<string>("FormValues") ?? "";

The request works fine if I select Key/Value as the format but I need Json.

Edit: Should add that I tried the valid Json format (JsonLint) plus the examples I gave, with and without spaces and using ' instead of " but it's still empty.


Solution

  • Quick fix:

    (( "value": [(( "@search.action": "delete", "id": "abc - 008" ))] ))
    

    Explanation: This is actually an awkward side-effect of how Orchard handles tokens within workflows. Take with a pinch of salt because I have a bad memory but I think it goes like this. So before data is sent to the individual workflow activities, the Workflows module executes the tokens stored. This means all your JSON stored is thrown away because Orchard thinks it is a token (Orchard tokens are formatted so: {Content.Body} etc.) and tries to execute it. I discovered this when trying to store a complex object within a workflow activity and had to hack around the issue. I meant to report it as an issue but I think I forgot (my bad), but seeing this makes me think it is a bug really. So why does the above work? Some selfish genius clearly ran into this issue and updated the code with this hack line:

    var json = formValues.Replace("((", "{").Replace("))", "}");
    

    Then left the UI saying:

    For JSon, enter a valid JSon string

    Massive fail.

    To correct my earlier laziness, I've created two issues regarding this. https://github.com/OrchardCMS/Orchard/issues/7760 https://github.com/OrchardCMS/Orchard/issues/7759