Expand my Community achievements bar.

Join us on September 25th for a must-attend webinar featuring Adobe Experience Maker winner Anish Raul. Discover how leading enterprises are adopting AI into their workflows securely, responsibly, and at scale.

Store custom action response to a variable

Avatar

Level 2

Hey There!

       I have a custom action which returns payload in the below format (as a contextual attribute)

 

{
"data": {
     "products": {
            "products": [
                  {
                      "productId": "111",
                      "title": "sample-title",
                       "url": "sample-url"
                  }
            ]
       }
}

I can traverse through this object using each loop and access the inner objects like below

{{#each context.journey.actions.3826ab4b-218b-476a-829b-fc07fc7790d3-1753790791486-1.data.products.products as |product|}}
   {% let id = product.productId %}
{{/each}}
 
However, when I try to store the contextual attribute to a variable, this error happens
{% let contextVar = context.journey.actions.3826ab4b-218b-476a-829b-fc07fc7790d3-1753790791486-1 %}
Error:
Invalid syntax Invalid syntax Error in parsing PQL expression "context.journey.actions.3826ab4b-218b-476a-829b-fc07fc7790d3-1753790791486-1": line 1:23 mismatched input '.3826' expecting {<EOF>, '*', '/', '%', '+', '-', '(', '.', '[', '>', '>=', '<', '<=', '!=', '?:', '=', And, Or, Occurs, In, Like, Matches, 'notIn'}. Error beginning at position: Line 36, Character 1
 
This happens even if I try to store a simple string value returned by custom action. Kindly let me know whether the variable should be defined differently or the contextual attributes can't be stored as of now. Thanks
 
 
2 Replies

Avatar

Employee Advisor

@IamCGK  

Error in parsing PQL expression "context.journey.actions.3826ab4b-218b-476a-829b-fc07fc7790d3-1753790791486-1"...

is caused by the fact that contextual attributes with hyphens and numbers in their keys (like 3826ab4b-218b-476a-829b-fc07fc7790d3-1753790791486-1) cannot be referenced directly in PQL expressions or variable definitions using the dot . notation. This limitation is due to PQL’s identifier syntax—it expects keys not to start with a number or contain hyphens unless bracket notation is used.

Correct way to reference such keys

To access values for keys containing hyphens, you must use bracket notation. Try referencing your contextual attribute like this: {% let contextVar = context.journey.actions["3826ab4b-218b-476a-829b-fc07fc7790d3-1753790791486-1"] %}

For nested attributes, continue with bracket notation:

{% let products = context.journey.actions["3826ab4b-218b-476a-829b-fc07fc7790d3-1753790791486-1"].data.products.products %}

 

 Contextual attributes cannot always be stored as variables if their key naming violates identifier rules .

Avatar

Level 2

Thanks for the reply. I've tried the above methods too, however still facing errors. 

Accessing just the object:
{% let contextVar = context.journey.actions["3826ab4b-218b-476a-829b-fc07fc7790d3-1753790791486-1"] %}

Err: 
Invalid syntax filter should be applied to an expression of type ARRAY or MAP. Was OBJECT. Error beginning at position: Line 12, Character 3
 
Accessing nested objects:
{% let contextProdVar = context.journey.actions["3826ab4b-218b-476a-829b-fc07fc7790d3-1753790791486-1"].data.products.products %}


Err: Invalid syntax filter should be applied to an expression of type ARRAY or MAP. Was OBJECT, Missing schema field: "data". Fields in the schema are [3826ab4b-218b-476a-829b-fc07fc7790d3-1753790791486-1, 3826ab4b-218b-476a-829b-fc07fc7790d3-1753790791486-4]. Error beginning at position: Line 12, Character 3