Version | 2.149 and up |
---|
The Campaign Builder feature is currently in an open beta status. If you like to take a look into this feature feel free to do so. 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. |
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.
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.
Please take note that you will need technical knowledge to implement this in your ADvendio instance. |
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 | ❌ | ✅ |
Please follow the instructions below to build your custom javascript file.
Any custom JavaScript for the campaign builder starts out as the following skeleton.
window.advendioCampaignBuilder = campaignBuilder => { // TODO }; |
The skeleton is a method named advendioCampaignBuilder
. The method will be called by the campaign builder and pass a CampaignBuilder
object to your method.
The campaignBuilder
is the API to interact with the campaign builder. You can listen on field changes, get field values, and set field values.
updateFieldFromRecord(record, fieldpath, value)
Set a specific value directly in the record object based on the field path.
getFieldFromRecord(record, fieldpath)
Get a specific value from the record object based on the field path.
async query({objectName,fields,limit,offset,conditions = [],orderByField,orderByDirection}
Run a SOQL query by parameters.
Consider this case where the maximum discount for a campaign item is 10%. The following script will:
Listen to any changes on a specific discount__c
field
Inside the listener, if the new discount value is over 10%
Set the discount__c
field for the item to 10
or the value from
if it is less
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)); } }); }; |
To query data from records that are not included in the campaign builder, you can use the campaignBuilder.query
method.
To prevent security vulnerabilities, the query
method is invoked with an object instead of a plain SOQL string.
To prevent security vulnerabilities, the query
method is invoked with an object instead of a plain SOQL string.
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 }; |
Once you have created your static resource js, you can upload it to your org via Setup > Static Resources > New.
After the successful upload please go to the uploaded file by hitting the “View file” link for your static resource.
Copy the latter part of the URL starting from “/resource”, e.g.
/resource/1610556603123/ADvendio__CampaignBuilderCJS? |
and then an administrator can enable it in the ADvendio Administration Settings.
Open the App Launcher.
Search for Administration Settings and open them.
Switch to the Administration Settings tab.
Next to Custom JavaScript (Campaign Builder), enter the link you copied from the URL in the step at the top of this section.
Click the Save button at the top of the page.
Now, the next time you start the campaign builder, your custom logic will be loaded.