This custom action adds an Attachment from any object that can have them. Use this on the level of the object you wish to attach something to. This will open a new window for each selected record, where you can add a Salesforce attachment using the native Salesforce attachment mechanisms.
Warning
This will show up on the Action Menu for all objects that allow attachments.
Use Cases
This is currently the main method for adding an attachment to a group of records via the Conga Grid. This will open a new window/browser tab for each selected record, allowing a different attachment to be added to each selected record.
Steps
crmc.require(["KendoEntry", "KendoPopup", "ListButton", "sfdc"], function(prompt, popup, navigate, sfdc) {
crmc.addCustomAction({
"itemID": "AG_AttachFile",
"isAvailable": function (context) {
var multipleSelected = context.selectedRows && context.selectedRows.length > 0 && context.selectedRows.length <= 5;
if (multipleSelected && this.featureSecurity.getSetting(context.objectDescribe.name, this.itemID) !== false){
var children = context.objectDescribe.childRelationships;
for (var i = 0; i < children.length; i++) {
if (children[i].childSObject == 'Attachment'){
return true;
}
}
}
return false;
},
"getLabel": function (context) {
return "Attach File";
},
"createSubmenuItems": function (context) {
return [];
},
"click": function (context) {
var ids = [];
context.selectedRows.map(function(row) {
ids.push(row.Id);
});
var nameField = sfdc.getSObjectNameField(context.objectDescribe);
var data = sfdc.query("SELECT Id,"+ nameField +" FROM "+context.objectDescribe.name+" WHERE Id IN('" + ids.join("','") + "')");
for (var i = 0; i < data.length; i++) {
var row = data[i];
if(row[nameField] !== undefined && row[nameField] !== null){
window.open("/p/attach/NoteAttach?pid=" + row.Id+"&parentname="+encodeURIComponent(row[nameField]));
}
else{
window.open("/p/attach/NoteAttach?pid="+row.Id);
}
}
}
});
});