Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 8 Next »

iHub cloud used https://handlebarsjs.com/ as template language.

This is an extension to Mustache and have few smart functions.

Smart functions

{{{toCSV list 'propertyName' 'quotes'}}}

Creates a csv of the array.
example{{{toCSV payload 'name' '"'}}} would take an array of object and use the name property with double quotes to create a csv, like this "Peter","Rickard"

Based on a payload like this

[
{"name":"Peter"},
{"name":"Rickard"}
]

{{toJSON object}} or {{JSONstringify object}}

Runs JSON.stringify(object) on the object.
Good to use in cases where you get an output like [object Object],[object Object]

example and object like this {payload:[{ value: "foo" },{ value: "bar" }]} with the mustache {{{toJSON payload}}} would resolve in [{"value":"foo"},{"value":"bar"}] instead of [object Object],[object Object]

Example sending full issue as json

{
    "issue":{{{toJSON issue}}}
}

"{{{flowVarMerge output _flow 'property_in_flow' 'new_name_in_scope'}}}"

This mustache function is a special one used mainly to insert flow variables into the output object. The output object is any object in the scope, usually payload or scope.something

Example if the payload variable is a list like below

[{"name":"A","id":"1"},{"name":"B","id":"2"}]
and you have a _flow variable collected in earlier actions like this:
["A":['n1','n2'],"B":['n3']]

Then when using this syntaxr

"{{{flowVarMerge payload _flow 'name' 'newProp'}}}"

The function will output

[{"name":"A","id":"1","newProp":['n1','n2']},{"name":"B","id":"2","newProp":['n3']}]

See all Math functions

"{{#eq 1 1}}YES{{/eq}}" tests if 1 eq 1 and return YES

{{add 1 1}} results in 2

See all Dates functions

Moment date functions

{{date "5 years ago" "YYYY"}} resolves current year - 5

{{moment format="HH:mm:ss"}} 16:34:56

See all helpers

Handlebars is extended with all the helpers in the link

getElementsByTagNameNS

This function returns the content of a element.
"{{{getElementsByTagNameNS variable 'xmlns' 'elementname'}}}"
Note the quotes.

It return the whole child element back, like the example below
<m:NumberToWordsResult xmlns:m="http://www.dataaccess.com/webservicesserver/">first </m:NumberToWordsResult><m:NumberToWordsResult xmlns:m="http://www.dataaccess.com/webservicesserver/">dummy</m:NumberToWordsResult>

getElementByTagNameNS

This function returns the content of a element.
"{{{getElementByTagNameNS variable 'xmlns' 'elementname' index}}}"
Note the quotes.

Example if we have a parent that has this soap response

`
    <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
      <soap:Body>
        <m:NumberToWordsResponse xmlns:m="http://www.dataaccess.com/webservicesserver/">
          <m:NumberToWordsResult>five million seven hundred and ninety four thousand two hundred and fifty nine </m:NumberToWordsResult>
        </m:NumberToWordsResponse>
      </soap:Body>
    </soap:Envelope>`

Then we can use the below syntax to pick the value “five million seven hundred and ninety four thousand two hundred and fifty nine”

"{{{getElementByTagNameNS payload 'http://www.dataaccess.com/webservicesserver/' 'NumberToWordsResult' 0}}}"

Lets break it down;

  1. getElementByTagNameNS is the function

  2. payload is the parent response of an action that is added to a variable called payload, this will now have the value of the soap message.

  3. The next argument is the xmlns of a tag

  4. The next argument is the Child element that you want to get

  5. The last argument is the index of the childs in the xmlns, could be many but in this case just one.

  • No labels