Send to Pardot
It loops through every row and passes the ID and field data into URLs. If more than 10 are selected, it will batch process URLs to avoid invalid URLs.
crmc.addCustomAction({ "itemID": "SendToPardot", "isAvailable": function (context){return this.featureSecurity.getSetting(context.objectDescribe.name,this.itemID)!==!1}, "getLabel": function (context){return"Send to Pardot"}, "createSubmenuItems": function (context){return[]}, "click": function (context){ var makeURL = function(row, retUrl) { var email = encodeURIComponent(row.Email); var id = encodeURIComponent(row.id); var partnerSrv = encodeURIComponent(context.actionGrid.settings.Partner_Server_URL_290); var session = encodeURIComponent(sforce.connection.sessionId); // console.log('Email: ' + row.Email + ', ID: ' + row.id); // console.log('Session: ' + session); // console.log('Partner Server: ' + partnerSrv); return 'https://pi.pardot.com/prospect/sync/email/'+ email +'?contact_id='+ id +'&sessionid='+ session +'&serverurl='+ partnerSrv +'&redirect_location=' + encodeURIComponent(retUrl); } var windows = []; var rowsProcessed = 0; var batchCount = Math.ceil(context.selectedRows.length / 10); var timer = setInterval(function () {Monitor()}, 500); var queue = []; for (var i = 0; i < batchCount; i++) { var tUrl = window.location; var batch = Between(rowsProcessed, context.selectedRows); batch.map(function(row) { if(row != undefined){ tUrl = makeURL(row, tUrl); } }); rowsProcessed += batch.length; queue.push(tUrl); }; function ProcessUrl(url){ windows.push(window.open(url)); windows[windows.length - 1].addEventListener('load', function() { windows[window.length - 1].close(); }, false); } function Between(start, array){ var end = start + 10 var list = []; for (var i = start; i <= end - 1; i++) { if(i > array.length - 1){ break; } else{ list.push(array[i]); } } return list; } function Monitor(){ if(queue.length > 0){ if(windows.length < 5){ PushBatch(undefined); } }else if(queue.length == 0){ clearTimeout(timer); alert("Sync to Pardot has finished! Please wait for the remaining windows to close automatically :)"); } //Some Loading bar code here... } function BatchComplete(index){ windows[index].close(); PushBatch(index); } function PushBatch(index){ if(index == undefined){ windows.push(window.open(queue.shift())); var index = windows.length - 1; windows[index].addEventListener('load', function() { BatchComplete(index); }, false); } else{ if(queue.length > 0){ windows[index] = window.open(queue.shift()); windows[index].addEventListener('load', function() { BatchComplete(index); }, false); } } } }});///Old// crmc.addCustomAction({// "itemID": "SendToPardot",// "isAvailable": function (context){return this.featureSecurity.getSetting(context.objectDescribe.name,this.itemID)!==!1},// "getLabel": function (context){return"Send to Pardot"},// "createSubmenuItems": function (context){return[]},// "click": function (context){// var makeURL = function(row, retUrl) {// email = encodeURIComponent(row.Email);// id = encodeURIComponent(row.id);// var partnerSrv = encodeURIComponent(context.actionGrid.settings.Partner_Server_URL_290);// var session = encodeURIComponent(sforce.connection.sessionId);// // console.log('Email: ' + row.Email + ', ID: ' + row.id);// // console.log('Session: ' + session);// // console.log('Partner Server: ' + partnerSrv);// return 'https://pi.pardot.com/prospect/sync/email/'+ email +'?contact_id='+ id +'&sessionid='+ session +'&serverurl='+ partnerSrv +'&redirect_location=' + encodeURIComponent(retUrl);// }// var url = window.location;// if(context.selectedRows.length > 10){// console.log("Sorry, 10 records or less :(");// alert("Sorry, 10 records or less :(");// }// else{// context.selectedRows.map(function(row) {// url = makeURL(row, url);// });// window.location = url;// }// }// });
