Scripts within tasks (phases)
With scripts attached to specific tasks, you can intervene in the task flow, for instance you could skip or add a task depending on a certain criteria or modify data. There are several functions available for triggering your code logic:
- onUpdate(): This script function is available inside every task and is executed when an update to a contact is made. It is useful if you want to skip a task or set the task status depending on data inside the contact.
- takes the flat view of the data object as argument
- returns an object that is applied as an update to the contact.
- transform(): Inside email, export and webhook tasks you can set a transform-function() that is called before the data is given to the rest of the task. You will need this function every time you must apply non-standard formatting to output fields.
- takes the flat view as argument
- returns the modified flat view or a different object. In "export" tasks you can also return an array of objects with each result in a separate output line. This is useful when making multiple sales in one phone call.
- sort(): This function is only availabe inside the export task. It can be used to sort the rows of the export.
- takes an array of the export data as argument
- returns a sorted array of export rows
- respToUpdate(): available in callanalyzer tasks. It can process answers from parties to whom the data has been passed
- --> is triggered when the called service sends back a response.
Example
function onUpdate(data){
if (data.$status == "success" && (data.$status_detail== "Unterlagen" || data.$status_detail== "Unterlagen_per_Post" ) && !ergebnisfeld_4) {
var to_update = "--- UNTERLAGEN --- " + data.notiz;
return {
ergebnisfeld_4: to_update
};
}
return {};
}
!ergebnisfeld_4 ensures that the function is only triggered if result field_4 is empty. without this a the code results in a recursive loop.