Pages

Thursday, November 28, 2019

Einstein Analytics: Binding serialization functions asString() or asObject()

We discussed the quest for here and the syntax here, and you may see we use asString() and asObject() in the samples, as per Einstein Analytics documentation:

asString() Function
Serializes a scalar, one-dimensional array, or two-dimensional array as a string. Escapes double quotes in strings.

asObject() Function
Passes data through with no serialization. Returns data as an object (an array of strings).

But, let us see in samples:

Selection binding with a value
Static Step
     "static_Owner_Manager": {
                "broadcastFacet": true,
                "label": "static_Owner_Manager",
                "selectMode": "singlerequired",
                "start": {
                    "display": [
                        "Owner"
                    ]
                },
                "type": "staticflex",
                "values": [
                    {
                        "display": "Owner",
                        "value": "Owner.Name",
                        "text": "Count Owner Name"
                    },
                    {
                        "display": "Manager",
                        "value": "Owner.Manager.Name",
                        "text": "Count Owner Manager Name"
                    }
                ]
            }

Binding
"groups": [
"{{cell(static_Owner_Manager.selection, 0, \"value\").asString()}}"
]

However using asObject() will Not throw error too
"groups": [
"{{cell(static_Owner_Manager.selection, 0, \"value\").asObject()}}"
]


"measures": [
                [
                    "sum",
                    "{{cell(static_Owner_Manager.selection, 0, \"value\").asString()}}"
                ]
]

The same, using asObject() will Not throw error too
"measures": [
                [
                    "sum",
                    "{{cell(static_Owner_Manager.selection, 0, \"value\").asObject()}}"
                ]
]


Selection binding with multiple values
Sample 1: selection binding in groups
Static Step
"staticTime_DATE": {
                "broadcastFacet": true,
                "label": "staticTime_DATE",
                "selectMode": "singlerequired",
                "start": {
                    "display": [
                        "Month"
                    ]
                },
                "type": "staticflex",
                "values": [
                    {
                        "display": "Month",
                        "value": [
                            "DATE_Year",
                            "DATE_Month"
                        ]
                    },
                    {
                        "display": "Week",
                        "value": [
                            "DATE_Year",
                            "DATE_Week"
                        ]
                    }
                ]
            }

Binding
"groups": [
"{{ cell(staticTime_DATE.selection, 0, \"value\").asObject() }}",
"field_name__c"
]

Sample 2: selection binding in measures
Static Step
"static_Amount_Count": {
                "broadcastFacet": true,
                "label": "static_Amount_Count",
                "selectMode": "singlerequired",
                "start": {
                    "display": [
                        "Amount"
                    ]
                },
                "type": "staticflex",
                "values": [
                    {
                        "display": "Amount",
                        "value": [
                            "sum",
                            "Amount"
                        ]
                    },
                    {
                        "display": "Count",
                        "value": [
                            "count",
                            "*"
                        ]
                    },
{
                        "display": "Unique",
                        "value": [
                            "unique",
                            "Id"
                        ]
                    }
                ]
            }

Binding
"measures": [
"{{ cell(static_Amount_Count.selection, 0, \"value\").asObject() }}"
                   ]


In short:
- use asString() when you only bind a string value
- use asObject() when you only bind multiple values
- use asObject() when you bind not a string value, such as true / false


Side note: old-style binding
"{{ value(selection(static_2)) }}"
equal to
"{{ cell(static_2.selection, 0, \"value\").asObject() }}"
equal to
"{{ column(static_2.selection, [\"value\"]).asObject() }}"

Side note: column binding
"{{ cell(static_Order_By.selection, 0, \"value\").asString() }}"
equal to
"{{ column(static_Order_By.selection, [\"value\"]).asObject() }}"




Reference:


Page-level ad