The documentation indicates we should escape all strings when building PUT, POST, and PATCH requests. I know this is best practice, but I'm running into a sort of race condition with it.
In my data action, I'm doing a PATCH request to Salesforce to update a Case record. Because I want the Data Action to be modular, I'm actually designing our flow so that we have a "Get Salesforce Case" data action with all the fields we use in Genesys, and the Update Salesforce Case action will take the values from the Get data action and only replace those if we need to, within the architect flow.
The actual issue is that some of these fields can be legitimately null, however, I either have a syntax issue in my Velocity template or there's a design issue with using $esc.jsonString when that string could be empty some of the time.
Here's the template I'm using. I've tried both the $
and $!
notation for the variables, but the action always fails if any of the fields is legitimately null.
{
"Subject": "$esc.jsonString($!{input.Subject})",
"Product__c": "$esc.jsonString($!{input.Product__c})",
"Reason": "$esc.jsonString($!{input.Reason})",
"Lang__c": "$esc.jsonString($!{input.Lang__c})",
"Origin": "$esc.jsonString($!{input.Origin})",
"SuppliedPhone": "$esc.jsonString($!{input.SuppliedPhone})",
"Supplied_Country__c": "$esc.jsonString($!{input.Supplied_Country__c})",
"Description": "$esc.jsonString($!{input.Description})",
"Status": "$esc.jsonString($!{input.Status})",
"Bypass_Survey__c":$input.Bypass_Survey__c
}
When one of the fields is null, the platform throws this error. In this case, Lang__c
was null as an input. I've worked around this for Description
which is the most risky not to escape, from within Architect by checking IsNotSetOrEmpty and writing empty
as a literal string (not ideal, though).
{
"message": "Substitution values invalid in action config. Invocation of method 'jsonString' in class com.inin.integrations.hedwig.data.variables.VariableVelocityEscapeTool threw exception java.lang.NullPointerException: Cannot invoke \"String.length()\" because \"input\" is null at BodyTemplate[line 5, column 20] A common reason for this error is needing to prepend the variable with 'input.' or 'credentials.'",
"code": "invalid.substitution",
"status": 400,
"messageParams": {},
"contextId": "32c205e7-8eda-4681-befd-bcc33039c73e",
"details": [
{
"errorCode": "ACTION.PROCESSING"
}
],
"errors": []
}