Skip to content

Instantly share code, notes, and snippets.

@anil826
Last active October 30, 2019 05:43
Show Gist options
  • Save anil826/a0e0f80822c3e710fea51aa8061979ef to your computer and use it in GitHub Desktop.
Save anil826/a0e0f80822c3e710fea51aa8061979ef to your computer and use it in GitHub Desktop.
DFG Intergration Contact
//Static records
var record_ids = ['000000002','000000001'];
//Contact Data
var contact_data = null;
// Generic function to make an AJAX call
var DFG_Get_Entity = function(user_token ,record_ids) {
// Return the $.ajax promise
return $.ajax({
url: 'https://test.dfg152.ru:8443/dfg-rest/entity/batch/get',
cors: true,
headers: {
'x-auth-token': user_token,
'x-organization': 'Syngenta',
'content-type': 'application/json'
},
data: JSON.stringify(record_ids),
method:'POST',
success: function(records){
//Collect contact record for formyoula repeat element.
var contact_record = [];
//Data
for(var index=0; index < records.length; index++ ){
//Collect the outer data for repeat group
var id = records[index].id;
var externalID = records[index].externalId;
var typeId = records[index].typeId
//Loop for contact data
for(var contact_index=0; contact_index < records[index].data.length; contact_index++ ) {
//Add external data to array
records[index].data[contact_index].id = id;
records[index].data[contact_index].externalId = externalID;
records[index].data[contact_index].typeId = typeId;
//Print the data
console.log(records[index].data[contact_index])
contact_record.push(records[index].data[contact_index])
}
if (contact_record.length > 1) {
//Add items
add_repat_item(contact_record.length, "82cb-1e7c-b50f","5e5a-267b-67f5", "f312-0284-625c", "b9ce-747f-4b73", "0acd-2bdb-efc7", "d826-6725-30e8", contact_record);
}
}
}
})
}
//Add data as repeat group in formyoula element.
function add_repat_item(repeat_item_length,component1,component2,component3,component4,component5,component6, contact_data){
for(i=1; i<=repeat_item_length; i++){
//Set value
formyoula.form_fields[component1].set({"value": contact_data[repeat_item_length].externalId});
formyoula.form_fields[component2].set({"value": contact_data[repeat_item_length].id});
formyoula.form_fields[component3].set({"value": contact_data[repeat_item_length].typeId});
formyoula.form_fields[component4].set({"value": contact_data[repeat_item_length].fieldId});
formyoula.form_fields[component5].set({"value": contact_data[repeat_item_length].key});
formyoula.form_fields[component6].set({"value": contact_data[repeat_item_length].value});
//Add repeat items
$(".add").click()
//remove default value
if(i == repeat_item_length) {
formyoula.form_fields[component1].set({"value": ""});
formyoula.form_fields[component2].set({"value": ""});
formyoula.form_fields[component3].set({"value": ""});
formyoula.form_fields[component4].set({"value": ""});
formyoula.form_fields[component5].set({"value": ""});
formyoula.form_fields[component6].set({"value": ""});
}
}
};
//DFG Get Entity records
DFG_Get_Entity(user_token, record_ids);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment