Skip to content

Instantly share code, notes, and snippets.

@melamriD365
Last active April 29, 2019 16:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save melamriD365/2502561d72505d6edc3a416c4435c78d to your computer and use it in GitHub Desktop.
Save melamriD365/2502561d72505d6edc3a416c4435c78d to your computer and use it in GitHub Desktop.
Change fetchXml for a subgrid dynamically
/*----------------------------------------
Change fetchXml for a subgrid dynamically
-----------------------------------------*/
function FetchViaName(executionContext) {
var formContext = executionContext.getFormContext();
var tabObj = formContext.ui.tabs.get("tab_summary");
var secObj = tabObj.sections.get("sec_contactCompaigns");
secObj.setVisible(false)
var fullname = formContext.getAttribute("fullname").getValue();
console.log("FullName: "+fullname)
var contactCompaigns = window.parent.document.getElementById("ContatCompaigns");
if (contactCompaigns == null) {
setTimeout(function () { FetchViaName(executionContext); }, 2000);
return;
}
else {
var fetchXml = '<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="true">' +
'<entity name="campaign">' +
'<attribute name="name" />' +
'<order attribute="name" descending="true" />' +
'<link-entity name="campaignitem" from="campaignid" to="campaignid" visible="false" intersect="true">' +
'<link-entity name="list" from="listid" to="entityid" alias="al">' +
'<link-entity name="listmember" from="listid" to="listid" visible="false" intersect="true">' +
'<link-entity name="contact" from="contactid" to="entityid" alias="am">' +
'<filter type="and">' +
'<condition attribute="fullname" operator="eq" value="'+fullname+'"'+'/>' +
'</filter>' +
'</link-entity>' +
'</link-entity>' +
'</link-entity>' +
'</link-entity>' +
'</entity>' +
'</fetch>';
if (contactCompaigns.control != null) {
//Here i set the fetchxml directly to subgrid
contactCompaigns.control.SetParameter("fetchXml", fetchXml); //set the fetch xml to the sub grid
contactCompaigns.control.Refresh(); //refresh the sub grid using the new fetch xml
secObj.setVisible(true)
}
else {
setTimeout(function () { FetchViaName(executionContext); }, 2000);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment