Calling Data Action from workflow - Invalid JSON

Hi Team,

The scenario is when the conversation is finished, insert notes into CRM system including Genesys notes and wrapup code + emails and messages would have a subject and body.

I have configured a Trigger which calls a workflow each time the userend event fires on a few ACD Queues. Whilst this works great sometimes, it often results in a 400 or 404 response to both Genesys Data Actions to extract the message / body / wrapcode / notes etc and the 3rd party web services to write the information.

For example, if a field was empty, I might get an error like:
JSON failed schema validation for the following reasons: Schema: # @/properties/messageId. Error location: /messageId. instance type (null) does not match any allowed primitive type (allowed: ["string"])
(I've worked around these in the Failure path of the Call Data Action within the workflow e.g. if failure, set field to "(no notes)" etc

A special character like # or even a line return \r\n in the textBody or htmlBody of an email cause the JSON to fail with:
Processing the Request Body Template resulted in invalid JSON.

Of significance, I can test the Data Action with the same parameters including # and/or \r\n and it works fine. It seems to be that the workflow can't construct valid JSON so doesn't even get to the point of calling the data action.

Have also experimented with default values which didn't help at all.

Lastly, the email subject and body are set by the customer. It feels like I would need to parse and adjust for special characters or not attempt to include those fields in the CRM notes. Any suggestions would be appreciated. Am rather stumped by this one since the Data Action tests are working fine.

Hi @beeScottie
Special characters in Velocity Template Language need to be escaped. The macros for escaping special chars are documented here: Velocity macros for data actions - Genesys Cloud Resource Center
Of which I think $esc.jsonString and $esc.hash can help here.

Hi @jacobshaw,

Thanks for the response. I was aware of these macros but understood them to be for the Data Actions themselves. The problem here is the JSON constructed by the workflow to call the Data Action is the bit that fails.

I actually need to escape quote an expression in a flow e.g.

"conversationId: " + Flow.conversationId + "

" +
"agentNotes: " + $esc.jsonString(Flow.agentNotes) + "

" +
"Email body: " + $esc.jsonString(Flow.emailBody)

The above expression is what get's written into the body of the CRM notes and displays as HTML on the CRM web page. The problem fields are Flow.agentNotes and Flow.emailBody as both fields are free format for the customer / agent.

The expression won't accept the $esc.jsonString() and there doesn't appear to be any functions for json or esc characters that I've been able to find. Hence, feeling a bit stuck with this one.

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