Legacy Dev Forum Posts

 View Only

Sign Up

Success Template - URL Encoding

  • 1.  Success Template - URL Encoding

    Posted 06-05-2025 18:45

    stephenwalter17 | 2024-04-05 09:03:11 UTC | #1

    Hi - I have a data action that is invoked from a script and in the data action response is a URL that includes parameters. I then want to use that response url again in the script and need the response url properly encoded.

    I have tried to encode the url via the data action success template but without success - is this possible or do the velocity macros only work on the request side? The data action request itself to the endpoint is successful and I can see the elements I need all populated, and everything is ok without my attempts to encode the response urls.

    Thanks in advance


    Jason_Mathison | 2024-04-09 19:24:23 UTC | #2

    If you are asking if you can use a data action input in the final response, the answer is currently no. There is an idea for adding that here:

    https://genesyscloud.ideas.aha.io/ideas/OTB-I-405


    stephenwalter17 | 2024-04-19 12:56:59 UTC | #3

    Thanks Jason, not looking to use an input in the output, and looking to use an encode function in the output which doesn't seem to be supported?


    Jason_Mathison | 2024-04-19 15:05:29 UTC | #4

    All of the encoding functions are available in the response template. What exactly is going wrong?


    stephenwalter17 | 2024-04-25 10:48:17 UTC | #5

    Here is the response template I am using:

    {
      "translationMap": {
        "sessionId": "$.sessionId",
        "customerId": "$.customerId",
        "customerURL": "$.customerURL",
        "agentURL": "$.agentURL"
      },
      "translationMapDefaults": {
        "sessionId": "\"\"",
        "customerId": "\"\"",
        "customerURL": "\"\"",
        "agentURL": "\"\""
      },
      "successTemplate": "{\n\"sessionId\": ${sessionId}, \"customerId\": ${customerId}, \"customerURL\": ${customerURL}, \"agentURL\": ${agentURL}}"
    }

    This works. The two output urls have url parameters which I would want to escape before passing around but I have struggled to use a macro without generating an error in step 10 of the test:

    10. Apply output transformation: Transform failed to process result using 'successTemplate' template due to error:'Unexpected character ('%' (code 37)): expected a valid value (JSON String, Number, Array, Object or token 'null', 'true' or 'false') at [Source: REDACTED ...

    Can you suggest how I escape the urls - I may have the wrong macro but here is what I am trying:

    "successTemplate": "{\n\"sessionId\": ${sessionId}, \"customerId\": ${customerId}, \"customerURL\": $esc.urlFormEncode(${customerURL}), \"agentURL\": $esc.urlFormEncode(${agentURL})}"


    Jason_Mathison | 2024-04-25 20:52:23 UTC | #6

    I am playing with this now, but if you have a chance can you provide an example of the input that is failing. Feel free to change anything sensitive, but please make sure to keep anything like symbols or spaces.


    Jason_Mathison | 2024-04-25 21:04:43 UTC | #7

    The issue might be that you are trying to include the quotes in the customerURL and agentURL variables, instead of putting the quotes in the successTemplate like this:

    "successTemplate": "{\n\"sessionId\": ${sessionId}, \"customerId\": ${customerId}, \"customerURL\": \"$esc.urlFormEncode(${customerURL})\", \"agentURL\": \"$esc.urlFormEncode(${agentURL})\"}"

    --Jason


    stephenwalter17 | 2024-04-26 07:55:57 UTC | #8

    Thanks @Jason_Mathison, that has certainly moved me forward and I can now get the response. A little bit of trial and error and possibly one macro more than I need, I am here:

    ` "successTemplate": "{\n\"sessionId\": ${sessionId}, \"customerId\": ${customerId}, \"customerURL\": \"$!esc.jsonString($esc.html(${customerURL}))\", \"agentURL\": \"$!esc.jsonString($esc.html(${agentURL}))\"}"`

    My output in this case is (for customerURL) "https://my.host.com/Default.aspx?mt=self&sid=1234567890"

    ... so I just need to work out how to remove the " on each end, I am presuming this is carried in from the translationMap and with your suggestion I expect I now have two double quotes at the start and the end. The key part is the encoding of the & in the middle as this was where the response was truncated when passed into the agent script - this data action is being called from there as well as from Architect.

    Any thoughts?

    Here is a sample response from the service I am calling:

    {
      "agentURL": "https://my.host.com/AgentDesktop.aspx?sid=1234567890",
      "customerId": "a66839d2-c37a-4973-9dc8-2d2d9d01d34c",
      "sessionId": "1234567890",
      "customerURL": "https://my.host.com/Default.aspx?mt=self&sid=1234567890"
    }

    Many thanks,


    nehakakar | 2024-04-27 11:22:14 UTC | #9

    hey sorry for asking but really you got you solution because I think encoding the response URL directly within the data action success template is currently not supported. If I'm wrong, then please let me know too.


    Jason_Mathison | 2024-04-29 20:52:06 UTC | #10

    Hacking the quotes out in the success template like this seemed to work:

    \"customerURL\": \"$!esc.jsonString($esc.html(${customerURL.substring(1, ${customerURL.length()} - 1)}))\"

    --Jason


    stephenwalter17 | 2024-04-29 21:03:48 UTC | #11

    Nice :) - every day is a school day. Thanks for sticking with this, I see more that I can do with success templates now.


    system | 2024-05-30 21:04:26 UTC | #12

    This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.


    This post was migrated from the old Developer Forum.

    ref: 25579