Forum Discussion
TribsTribs
9 years agoQrew Member
try this code. it pulls data from a master table and adds them as child records
function ImportIAB( CampaignID) {
console.log("inside import" + CampaignID);
$.ajaxSetup({
async: false,
data: {
apptoken: APPTOKEN
}
});
var Promise = $.get(DBID_IAB, {
act: "API_DoQuery",
qid: "5" // execute Query ID# ?
});
$.when ( Promise ).then( function (xml) {
var data = $(xml);
// console.dirxml( data );
var CSV = "";
var records = data.find("record");
// adding the Parent record ID to the CSV data.
$.each(records,function ( index, record) {
var rowID = $('record_id_', record).text();
CSV = CSV + CampaignID + "," + rowID + "\n";
});
console.log(CSV);
//alert(CSV);
try {
var Promise1 = $.get(DBID_CampaignIAB,{
act: "API_ImportFromCSV",
records_csv: CSV,
skipfirst: 0,
clist: "6.10"
} );
} catch (e) {
console.log("Error",e);
}
console.log("Import Executed");
try{
$.when (Promise1).then( function (xml1) {
var import_count = $("num_recs_added", xml1).text();
window.location.hash = "tab_2";
window.location.reload(true);
});
} catch (e) {
console.log("Error",e);
}
});
return false;
}
function ImportIAB( CampaignID) {
console.log("inside import" + CampaignID);
$.ajaxSetup({
async: false,
data: {
apptoken: APPTOKEN
}
});
var Promise = $.get(DBID_IAB, {
act: "API_DoQuery",
qid: "5" // execute Query ID# ?
});
$.when ( Promise ).then( function (xml) {
var data = $(xml);
// console.dirxml( data );
var CSV = "";
var records = data.find("record");
// adding the Parent record ID to the CSV data.
$.each(records,function ( index, record) {
var rowID = $('record_id_', record).text();
CSV = CSV + CampaignID + "," + rowID + "\n";
});
console.log(CSV);
//alert(CSV);
try {
var Promise1 = $.get(DBID_CampaignIAB,{
act: "API_ImportFromCSV",
records_csv: CSV,
skipfirst: 0,
clist: "6.10"
} );
} catch (e) {
console.log("Error",e);
}
console.log("Import Executed");
try{
$.when (Promise1).then( function (xml1) {
var import_count = $("num_recs_added", xml1).text();
window.location.hash = "tab_2";
window.location.reload(true);
});
} catch (e) {
console.log("Error",e);
}
});
return false;
}