JavaScript Self-Referencing Campaigns
From All n One's bxp software Wixi
Self Referencing Campaigns are extremely useful tools to allow campaigns add dynamic information to their work day.
A self referencing data table shows all the previous records that match pre-specified search criteria.
The system uses AJAX, another word for complicated client side JavaScript. Being who we are in the BE support team, we've prepacked the whole lot and made it a couple of lines of work .
Contents
- 1 Step 1. Create a user for automated lookups
- 2 Step 2. Modify the campaign for external lookups
- 3 Step 3. Create a location in the script to display the results.
- 4 Step 4. Create the Self-Referencing Function.
- 5 Step 4.1. Create the Self-Referencing Function for use on an on change event on a (Text box,Drop down list, etc).
- 6 Step 5. Call the Self-Referencing Function.
- 7 Step 6. Data Injection Campaigns
1 Step 1. Create a user for automated lookups
We need a dedicated secure user in order to be used as the user to do these lookups.
The suggested user is called
- Firstname: Automated
- Surname: Lookup
- Password: make this incredicbly long and complicated, it will never be used.
- IP Range: This is vitally important. This system will only work from the IP addresses specified here.
- External System Id: automatic
- External System Key: passkey
Make sure NOTHING is ticked throughout the boxes below.
You also need to do the security jobs for the user.
- Add the user to the campaign.
- Ensure the user is added to the Everyone group in the Organogram in SAM.
2 Step 2. Modify the campaign for external lookups
By default the campaign will not be able to be searched externally. We need to enable this.
Main Menu > Database Management > Database - Primary Details > Campaign - Edit > Choose your campaign > Advanced Options subsection > Change "Externall Available" from Private to Public
Update the campaign.
3 Step 3. Create a location in the script to display the results.
The results have to be shown somewhere. This, to date, has been puti n the Notes section of a Section Header, somewhere in the script so..... add the following to a Notes section of a Section Header in your script.
<div id='strHistory'></div><script language=javascript type=text/javascript src=https://ww3.allnone.ie/library/javascript/fn_javascript_ajax_campaign.js ></script>
4 Step 4. Create the Self-Referencing Function.
You need to modify the code below for it to work for you.
This gets placed in the JavaScript onLoad of the campaign. Main Menu > Database Management > Database - Primary Details > Campaign - Edit > Choose your campaign > JavaScript onLoad subsection > Opening Code execution box.
/*--------------------------------------
// The Self Referencing Lookup settings
--------------------------------------*/
function fn_SelfReferencing() {
if (typeof aryAjax_Settings=="undefined")
alert("Library did not load");
else {
var strValue = document.getElementById('Some_Field_In_Script').value;
aryAjax_Settings[0] = "client_demo"; //The system to use
aryAjax_Settings[1] = "automatic"; //The automation username
aryAjax_Settings[2] = "passkey"; //The automation users password
aryAjax_Settings[3] = "1"; //The Id of the campaign
aryAjax_Settings[4] = "strCDA_1_field_0_0"; //The search field
aryAjax_Settings[5] = strValue; //The search value
aryAjax_Settings[13] = "-1"; //Id of the current record, used for delimiting and not repeating current case
aryAjax_Settings[14] = "true"; //Click through to campaign?
aryAjax_Settings[15] = "divWarning"; //The id of the destination to which the table will be inserted
aryAjax_Settings[16] = "Table"; //The types of processing. Table or Insert
//The fields to be returned into the array
//The column names of those fields
//The first field must always be the ID of the campaign
aryAjax_Settings[6] = "intCDA_1_Id,strCDA_1_field_0_0,strCDA_1_field_0_1";
aryAjax_Settings[12] = "Id,Field 1,Field 2";
aryAjax_Settings[17] = "intCDA_1_Id,strCDA_1_field_0_0,strCDA_1_field_0_1";
fn_Ajax_BE_Process();
}
}
5 Step 4.1. Create the Self-Referencing Function for use on an on change event on a (Text box,Drop down list, etc).
You need to modify the code below for it to work for you.
This gets placed in the JavaScript onLoad of the campaign. Main Menu > Database Management > Database - Primary Details > Campaign - Edit > Choose your campaign > JavaScript onLoad subsection > Opening Code execution box.
function fn_SelfReferencing() {
if (typeof aryAjax_Settings=='undefined')
alert('Library did not load');
else {
aryAjax_Settings[0] = 'client_XXXXXXX';//CLIENT NAME
aryAjax_Settings[1] = '';//ext username
aryAjax_Settings[2] = '';//ext password
aryAjax_Settings[3] = ' ';//ID OF THE CAMPAIGN TO LOOK UP IN
aryAjax_Settings[4] = ' ';//FIELD THAT YOU WANT TO SEARCH ON EG NAME OR PRODUCT CODE
aryAjax_Settings[5] = document.getElementById(' ').value;//THE FIELD THAT YOU WANT IN THE CURRENT CAMPAIGN EG IN CAMPAIGN (458) THE FIELD THAT YOU WANT TO PASS ON TO THE OTHER CAMPAIGN TO SEARCH ON
aryAjax_Settings[13] = '-1';
aryAjax_Settings[14] = 'true';
aryAjax_Settings[15] = 'strHistory';
aryAjax_Settings[6] = 'strCDA_XXXX_field_X_X,strCDA_XXXX_field_X_X,strCDA_XXXX_field_X_X';//FILDS IN THE OTHER CAMPAIGN THAT YOU WOULD LIKE TO TO FILL IN THE OTHER CAMPAIGN
aryAjax_Settings[12] = 'Id,Nom produit,Libellé marque,Famille';
aryAjax_Settings[16] = 'Insert';
aryAjax_Settings[17] = 'strCDA_458_field_X_X,strCDA_XXXX_field_X_X,strCDA_XXXX_field_X_X';//FILDS IN THE CURRENT CAMPAIGN THAT YOU WOULD LIKE TO BE FILLED IN FROM THE OTHER CAMPAIGN
fn_Ajax_BE_Process();
}
setTimeout(function() {
fn_CheckNull();
},550);
}
//************************************************************************************************************************************************
function fn_CheckNull(){
var strCDA_XXXX_field_0_9 = document.getElementById('strCDA_XXXX_field_X_X');//FIELD IN THE CURRENT CAMPAIGN THAT HAVE BEEN FILLED
var strCDA_XXXX_field_0_10 = document.getElementById('strCDA_XXXX_field_X_X');//FIELD IN THE CURRENT CAMPAIGN THAT HAVE BEEN FILLED
if((strCDA_XXXX_field_X_X.value == '')&&(strCDA_XXXX_field_X_X.value == '')){//FIELD IN THE CURRENT CAMPAIGN THAT HAVE BEEN FILLED, YOU CAN USE ONE OR TWO FILEDS THAT YOU KNOW ARWE FILLED IN SO YOU CAN TELL IF THE RECORD WAS THERE
alert('NOT FOUND');
}
}
6 Step 5. Call the Self-Referencing Function.
You now need to add the automated lookup to a field. This is usually done on the onChange of the value being looked up. i.e. if you search on a phone number, edit the phone number question and in the onChange of the box, add
fn_SelfReferencing();
And that should be it and you ready to test and use.
7 Step 6. Data Injection Campaigns
It is also possible to do data injection campaigns using this functionality. JavaScript_Data_Injection_Campaigns