Custom JS
DronaHQ gives a way to write custom Javascript on any data in the app to transform or generate data in the format that you need. You can make use of the JS libraries and JS objects here as well. The output of this JS will be seen in the transformed response section and will be the final output of the Data query for the rest of the app.
DronaHQ imported JS libraries
The following JS libraries are auto imported by DronaHQ to be used in the JS code:
Libraries | Links |
---|---|
underscore | https://underscorejs.org/ |
moment | https://momentjs.com/docs/ |
papaparse | https://www.papaparse.com/docs |
alasql | https://github.com/AlaSQL/alasql/wiki |
crypto | https://www.npmjs.com/package/crypto-js |
jquery | https://api.jquery.com/ |
Example usage
Imagine a scenario that you have a Tablegrid control with data already populated and you want to get all invoice numbers and populate them in a dropdown for users selection. Instead of doing a database or API call, you can create a custom JS type of a data query and take the Tablegrid data as input parameter to the JS code.
Tablegrid data
{
"customer_info": {
"customer field": "Customer data",
"unformatted_customer_field": " customer \n stuff ",
"total_value": "281.01",
"associated_usernames": ["user1", "myuser", "online_user"]
},
"payments": [
{
"invoice_number": "101301",
"date": "2022-09-11T16:12:34.494Z",
"description": "recurring subscription",
"amount": 110.48
},
{
"invoice_number": "101302",
"date": "2022-09-29T14:45:13.148Z",
"description": "one time purchase",
"amount": 24.49
},
{
"invoice_number": "101303",
"date": "2022-10-11T16:12:34.683Z",
"description": "recurring subscription",
"amount": 110.48
},
{
"invoice_number": "101304",
"date": "2022-10-12T11:45:22.182Z",
"description": "recurring subscription deluxe",
"amount": 35.56
}
]
}
JS code
function JSCode( output, sample ) {
output = sample.payments.map(payment => payment.invoice_number);
return output;
}
Output
[
"101301",
"101302",
"101303",
"101304"
]
This dataquery can be referenced in any control (e.g. dropdown) with the following to get the required array of string.
{{custom_js_dataquery}}
DronaHQ automatically imports moment.js, underscore.js, crypto.js, papaparse.js, alasql.js and jquery.js by default beyond which you can import your own libraries or script tags or build reusable JS functions using JS objects.