Einstein.ExecuteSAQLQuery

Parameter

Info

Method Name

You can give any name. This name will be displayed in the methods list.

Request Type

Einstein.ExecuteSAQLQuery

This is the method that you are using

Parameters

As explained in the previous table

Result Type

ListOfRecords (Auto Selected)

It indicates that the method can return one or more records

Record Limit

Numeric value (e.g. 10)

If Method is returning larger number of records, then you can limit this result by providing this value.

Record JsonPath

Each method returns data in json format and to pick any specific information from the json, we need to specify the Record JsonPath so Voice Worx platform will pick that data in consideration while displaying results.

Example: $.results.records[*]

This selects all the records that is returned.

Empty Result Template

When the method does not return any data, this response will be generated. So we can specify something like:

“Sorry, I could not find the data”

Record Template

Let’s assume that the following json represents a record.

{

  • "action" : query,

  • "responseId" : 4ZYb6WZm8DGZp_0fHwqHSV,

  • "results" : -{

    • "metadata" : +[ ... ],

    • "records" : -[

      • -{

        • "Quarter" : This Quarter,

        • "StageName" : Prospecting,

        • "stage_sort" : 1,

        • "sum_Amount" : 24597662,

        • "time_sort" : 1

},

      • +{ ... },

      • +{ ... },

      • +{ ... },

      • +{ ... },

      • +{ ... },

      • +{ ... },

      • +{ ... },

      • +{ ... },

      • +{ ... },

      • +{ ... },

      • +{ ... },

      • +{ ... },

      • +{ ... }

]

  • },

  • "query" : q = load \"0Fb2w000000HGNMCA4/0Fc2w000002C0f9CAC\";\nq = filter q by 'Stage.IsClosed' == \"false\";\nq = filter q by 'ForecastCategory' != \"Omitted\";\ntoday = filter q by 'IsLastUpdate' == \"1\";\ntoday = group today by 'StageName';\ntoday = foreach today generate 'StageName' as 'StageName', sum('Amount') as 'sum_Amount', last('Opportunity.Stage.SortOrder') as 'stage_sort', 0 as 'time_sort', \"Current\" as 'Quarter';\none = filter q by (date('ValidFromDate_Year', 'ValidFromDate_Month', 'ValidFromDate_Day') in [..\"1 quarters ago\"]) && (date('ValidToDate_Year', 'ValidToDate_Month', 'ValidToDate_Day') in [\"current quarter\"..]);\none = group one by 'StageName';\none = foreach one generate 'StageName' as 'StageName', sum('Amount') as 'sum_Amount', last('Opportunity.Stage.SortOrder') as 'stage_sort', 1 as 'time_sort', \"This Quarter\" as 'Quarter';\ntwo = filter q by (date('ValidFromDate_Year', 'ValidFromDate_Month', 'ValidFromDate_Day') in [..\"2 quarters ago\"]) && (date('ValidToDate_Year', 'ValidToDate_Month', 'ValidToDate_Day') in [\"1 quarter ago\"..]);\ntwo = group two by 'StageName';\ntwo = foreach two generate 'StageName' as 'StageName', sum('Amount') as 'sum_Amount', last('Opportunity.Stage.SortOrder') as 'stage_sort', 2 as 'time_sort', \"1 quarter ago\" as 'Quarter';\nthree = filter q by (date('ValidFromDate_Year', 'ValidFromDate_Month', 'ValidFromDate_Day') in [..\"3 quarters ago\"]) && (date('ValidToDate_Year', 'ValidToDate_Month', 'ValidToDate_Day') in [\"2 quarters ago\"..]);\nthree = group three by 'StageName';\nthree = foreach three generate 'StageName' as 'StageName', sum('Amount') as 'sum_Amount', last('Opportunity.Stage.SortOrder') as 'stage_sort', 3 as 'time_sort', \"2 quarters ago\" as 'Quarter';\nfour = filter q by (date('ValidFromDate_Year', 'ValidFromDate_Month', 'ValidFromDate_Day') in [..\"4 quarters ago\"]) && (date('ValidToDate_Year', 'ValidToDate_Month', 'ValidToDate_Day') in [\"3 quarters ago\"..]);\nfour = group four by 'StageName';\nfour = foreach four generate 'StageName' as 'StageName', sum('Amount') as 'sum_Amount', last('Opportunity.Stage.SortOrder') as 'stage_sort', 4 as 'time_sort', \"3 quarters ago\" as 'Quarter';\nresult = union today, one, two, three, four;\nresult = group result by ('Quarter', 'StageName');\nresult = foreach result generate 'StageName' as 'StageName', 'Quarter' as 'Quarter', sum('sum_Amount') as 'sum_Amount', first('stage_sort') as 'stage_sort', first('time_sort') as 'time_sort';\nresults = order result by ('time_sort' desc, 'stage_sort' asc);,

  • "responseTime" : 114

}

In this example, you want to access the items of records array,

So record template can be written as

{{StageName}}, amount {{sum_Amount}}

Note:

Anything written in between {{ }} is represented as a json field and it’s case-sensitive.

{{StageName}} is not same as {{stagename}}

Result Template

This indicates how method results should be represented.

Here you go, We have found the following historical pipeline by stage, {{Records}}

Here, {{Records}} represents one or more records separated by a separator.

Now the response looks like:

I have found the following historical pipeline by stage, Prospecting, amount 24597662, Qualification, amount 53942843, Needs Analysis, amount 64842060, Value Proposition, amount 29715331, Perception Analysis, amount 38981892, Proposal/Price Quote, amount 15889140, Negotiation/Review, amount 17044891, Prospecting, amount 24597662, Qualification, amount 53942843, Needs Analysis, amount 64842060

Last updated