...
Info |
---|
We are looking forward to your feedback as well as enhancement ideas. Please contact our Customer Success Management team or support@advendio.com to share feedback with us. |
Challenge
For performing custom calculations in our Campaign Builder in-built features like Salesforce formulas and the campaign builder layout settings may not suffice in certain use cases.
...
Solution
You can add additional behaviour and calculations by creating a JavaScript static resource that can be loaded into the campaign builder. A custom script allows you to react to field changes and to interact with the data in the campaign builder.
...
Note |
---|
Please take note that you will need technical knowledge to implement this in your ADvendio instance. |
When do I need to extend the campaign builder with a custom script?
Problem | Pre-Installed Campaign Builder | Custom JavaScript |
---|---|---|
Fast and configurable campaign item editing | ✅ | ✅ |
Conditional tab and field visibilities | ✅ | ✅ |
✅ | ✅ | |
Performing SOQL queries to fetch data | ❌ | ✅ |
Complex calculations in JavaScript | ❌ | ✅ |
Creating your custom javascript file
Please follow the instructions below to build your custom javascript file.
Static resource skeleton
Any custom JavaScript for the campaign builder starts out as the following skeleton.
...
The campaignBuilder
is the API to interact with the campaign builder. You can listen on field changes, get field values, and set field values.
Available methods
updateFieldFromRecord(record, fieldpath, value)
...
Run a SOQL query by parameters.
Discount limiting example
Consider this case where the maximum discount for a campaign item is 10%. The following script will:
...
Code Block |
---|
window.advendioCampaignBuilder = campaignBuilder => { // 1. Listen on changes on discount__c field campaignBuilder.on("advendio__rate_discount_4__c", async ({ recordId, from, to, record }) => { if (Number(to) > 10) { campaignBuilder.updateFieldFromRecord(record, "advendio__rate_discount_4__c", Math.min(to, 10)); } }); }; |
Querying additional data
To query data from records that are not included in the campaign builder, you can use the campaignBuilder.query
method.
...
Code Block |
---|
window.advendioCampaignBuilder = async (campaignBuilder) => { const result = await campaignBuilder.query({ objectName: 'Account', fields: 'Name', limit: 5, offset: 0, conditions: [{ fieldName: "Name", condition: "!=", value: "Acme", scapeQuotes: true }] }); console.log(result); // array of accounts }; |
Use your custom script
Once you have created your static resource js, you can upload it to your org via Setup > Static Resources > New.
...