Let's say I drop the requirement that this needs to be done while Agreement is not saved.
How would I do this if my Agreement is saved (existing) record in CRM.
I am trying to do it with JS but unable to get subgrid as JS object. This is my fucntion that gets called form onLoad()
function loadDefaultRecipients(defaultRecipients){
//get the subgrid
//CRM 2015
//var objSubGrid = document.getElementById("EnvelopeRecipientsTable");
//CRM 2015 Update 1
//var objSubGrid = window.parent.document.getElementById("EnvelopeRecipientsTable");
//Legacy forms
var objSubGrid = Xrm.Page.getControl("EnvelopeRecipientsTable");
//CRM loads subgrid after form is loaded so when we are adding script on form load, need to wait until sub grid is loaded
// that's why we are adding a delay
if (objSubGrid == null) {
setTimeout(function(){
loadDefaultRecipients(defaultRecipients);
}, 2000);
return;
} else {
alert("Subgrid is loaded...");
//when subgrid is loaded, get GUID
var GUIDvalue = Xrm.Page.data.entity.getId();
//Create FetchXML for sub grid to filter records based on GUID
var FetchXml = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>" +
"<entity name='cs_esignaturerecipient'>" +
"<attribute name='cs_routingorder' />" +
"<attribute name='cs_name' />" +
"<attribute name='cs_email' />" +
"<attribute name='cs_signertype' />" +
"<order attribute='cs_routingorder' descending='false' />" +
"<filter type='or'>";
for(var rec=0; rec<defaultRecipients.length; rec++){
FetchXml+= "<condition attribute='cs_email' operator='eq' value='" + defaultRecipients[rec] + "' />";
}
FetchXml+= "</filter>" +
"</entity>" +
"</fetch>";
//apply layout and filtered fetchXML
objSubGrid.control.SetParameter("fetchXml", FetchXml);
//Refresh grid to show filtered records only.
objSubGrid.control.Refresh();
}
}