Script transformation

Script transformation allows you to enable inline script transformation for Data loading endpoints and Service actions. Scripts can be configured to receive a response object obtained from the HTTP response and transform it to another response object depending on your target integration System of Record (SoR). Scripts cannot perform any requests or store any data. Scripting transformation is only intended to transform the response so that it can be parsed by the HTTP integration JSON parser.

  • Each HTTP endpoint has its own editable script.
  • When testing an HTTP integration with the Test Service button, the script is run along with the test request.
  • Scripts run with request transformation are limited to 10000 statements.
  • Script execution is also limited by the time period of one minute. If the script does not finish in this period, it is terminated.

Before you begin

Using the script transformation infers that you are familiar with your target application SoR. When using script transformation for HTTP integrations follow this general process:

  • Ready your script that you want to import via the Data loading or Service actions configuration pages.
  • Scripts must be prepared in the javascript language edited in your preferred text editor / development tool.
  • When ready, paste the script (or edit directly) via the script transformation box in the Microapps admin interface.
  • When imported, test the script.

Note:

When using script transformation, the standard script output is logged and indexed by Citrix for debugging purposes. Please ensure that no sensitive information is logged when using print, console.log and so on during configuration.

Enable script transformation

To enable script transformation when configuring either your Data loading or Service Actions follow these steps:

  1. Select the Script transformation button:

    Script transformation toggle

  2. Enter your prepared script:

    Script input

  3. Select Test with parameters followed by Test service to see the original response, script output, transformed response, and any script errors if applicable.

Note:

If you change the transformation script, you must regenerate the table as well

When your script is working correctly with your Data loading or Service actions select Add.

Example scripts

({response}) => {
_ = library.load("lodash")
let json = JSON.parse(response)
console.log(`loaded user count: ${json.length}`)
let transformed = json.filter(user => {
    if (user.active === true) {
        return true
    }
    console.log(`skipping inactive: ${user.displayName}`)
    return false
}).map(user => ({
    name: user.displayName,
    avatarUrl: user.avatarUrls["32x32"],
    now: _.now(),
}))
return JSON.stringify(transformed) }

Note:

You can return the string as in the preceding example or alternatively as the js object (array) that would return the transformed variable.

Example: Renaming JSON array name before.json after.json:

({
response
}) => {
_ = library.load("lodash")
 
function rename(obj, key, newKey) {
    if (_.includes(_.keys(obj), key)) {
        obj[newKey] = _.clone(obj[key], true)
        delete obj[key]
    }
    return obj
}
 
let json = JSON.parse(response)
let transformed = rename(json, 'tickets', 'new_tickets')
return JSON.stringify(transformed) }
Script transformation