How to apply custom FetchXML to a Subgrid using JavaScript - dynamics-crm

The implementation of applying custom FetchXML to a Subgrid appears to have changed from CRM 2011/13 to Dynamics 365. The change is with respect to GridControl.SetParameter().
I have followed many articles talking about this same issue but nothing is working at the moment on Dynamics 365 Online.
Is there any alternative method to achieve the same functionality?
In my below code, I am trying to fetch all of the phone call and email activities related to the account and show them on the Subgrid which is on the account form.
//Shows only the PhoneCall activities related to Organisation
//var allPhoneCallsGrid = window.parent.document.getElementById("AllPhoneCalls"); //Not supported by Microsoft
//var allPhoneCallsGrid = document.getElementById("AllPhoneCalls"); //Not Supported by Microsoft
var allPhoneCallsGrid = Xrm.Page.getControl("AllPhoneCallactivities"); //Sub-grid is on the Account Form
if (allPhoneCallsGrid == null) {
setTimeout(function() {
AccountForm.AccountFormOnLoad();
}, 2000); //if the grid hasn’t loaded run this again when it has
return;
}
var accountId = Xrm.Page.data.entity.getId();
var allPhoneCallsfetchXml = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>" +
" <entity name='activitypointer'>" +
" <attribute name='activitytypecode' />" +
" <attribute name='subject' />" +
" <attribute name='ownerid' />" +
" <attribute name='prioritycode' />" +
" <attribute name='regardingobjectid' />" +
" <attribute name='activityid' />" +
" <attribute name='scheduledstart' />" +
" <attribute name='scheduledend' />" +
" <attribute name='statecode' /> " +
" <attribute name='community' /> " +
" <order attribute='modifiedon' descending='false' />" +
" <filter type='and'>" +
" <condition attribute='activitytypecode' operator='ne' value='4206' />" +
" <condition attribute='activitytypecode' operator='eq' value='4210' />" +
" </filter>" +
" <link-entity name='incident' from='incidentid' to='regardingobjectid' alias='ad'>" +
" <filter type='and'>" +
" <condition attribute='account' operator='eq' uitype='account' value='" + accountId + "' />" +
" </filter>" +
" </link-entity>" +
" </entity>" +
"</fetch>";
allPhoneCallsGrid.control.SetParameter("fetchXml", allPhoneCallsfetchXml); //Unable to get property 'SetParameter' of undefined or null reference
//allPhoneCallsGrid.getGrid().setParameter("fetchXml", allPhoneCallsfetchXml);
allPhoneCallsGrid.control.Refresh(); //refresh the sub grid using the new fetch xml

Using Xrm page object, we can bind JavaScript to the onload event of the subgrid.
JavaScript can be bind to the subgrid using Ribbon Workbench tool.
For sample code, on how to write JavaScript on subgrid event, please refer this link
http://www.inogic.com/blog/2015/11/identify-the-trigger-for-an-on-load-event-for-sub-grid-in-dynamics-crm/

Community thread advised against this unsupported approach. Recommendation is to use RetrieveMultiple pre-operation plugin to intercept the call & pass our custom fetchxml query to achieve the result.
This is also having its own disadvantage, because of performance degradation by costly pre-event call & have to limit the exact retrieval call. But this is atleast in supported area.

Script on load form:
var control = Xrm.Page.getControl("Your Subgrid control");
var grid = control.getGrid();
var fetchXml = "<fetch version='1.0' output-format='xml-platform'
mapping='logical' distinct='false'>...</fetch>" //Your fetch Xml
grid.setParameter("fetchXML", fetchXml);

Related

Dynamic field validation message issue

1.I have added dynamic array field which changes on the dropdown. and I have added "required" in html
$.each(data.result, function (key, value) {
if (typeof value['filter'] !== "undefined") {
var id = value['filter']['id'];
var name = value['filter']['name'];
$(".label_filter2").append('<div class="form-group m-form__group"><label class="custom_form_label">' + name + '<span class="error_msg">*</span></label><input type="text" class="form-control m-input m-input--air filter_specification" name="filter[' + id + ']" placeholder="Enter ' + name + '" data-toggle="m-tooltip" required title="' + name + '"></div>');
}
});
2.Its totally work, but problem is validation message same like label.
https://www.screencast.com/t/Hqawm0Tae
3.I need "this field is require" message.I hope you are understand my question.Please help me.

Not able to set value in JSTL

from ajax response i am getting json string:
{"{\"nodeName\":\"abc\"}":[{"url":"abc","status":true},{"url":"abc","status":true}]," {\"nodeName\":\"pqr\"}":[{"url":"abc","status":true},{"url":"abc","status":true}]}
and i am parsing that json string from below mentioned code:
$.each(obj, function(key, arr) {
$.each(arr, function(_, v) {
alert(key +" "+ v.url +" "+v.status);
});
});
till now it works fine.
Now, using jstl i am setting the value of key, v.url and v.status inside $.each like this
<c:set var="status" value="${v.status}"/>
<c:set var="url" value="${v.url}"/>
<c:set var="nodeName" value="${key}"/>
alert("url =" +'${status}' + " key =" + '${nodeName}' + " status ="+ '${url}');
i am able to get the value of key(${nodeName}) on alert but no value for url and status.
Please suggest..

$.getJSON will not load JSON Data

http://jsfiddle.net/ADvCJ/124/ works without the $.getJSON so that tells me Im having a problem with $.getJSON to work. I searched all over the place and cannot find solution to this issue. Please help!
Other thing I noticed it duplicates the four items from JSON how do I stop duplicating them?
code
$(document).ready(function() {
$.getJSON("js/dataPokerPlayers.json", function(data) {
$.each(pokerplayers, function(i, data){
$(".tableData tbody").append("<tr><td>" + data.rank + "</td><td>" + data.name + "</td><td>" + data.earnings + "</td><td>" + data.points + "</td><td>" + data.totalearnings + "</td></tr>");
});
});
});
It looks like there were a couple of changes required.
Firstly, the table needed a <thead> around the heading row.
<table class="tableData">
<thead>
<tr>
<th>Rank</th>
<th width="250">Name</th>
<th>Earnings</th>
<th>Points</th>
<th>Total Earnings</th>
</tr>
</thead>
<tbody></tbody>
</table>
And secondly, the JSON URL wasn't really returning JSON; it was regular Javascript. var pokerplayers = needed to be removed from the start and ; removed from the end of the content.

classic ASP cookies and sessions returned as "undefined" only in Firefox on 64 bit OS. Why?

One my home works in my classic ASP class is to create a simple logon form, a page that processes the form by saving values to cookies, and then a display page that takes the values from the cookie, stores them into session variables and then displays the results in an html page.
I have found that this homework works properly in IE, Chrome, Opera, Safari, Maxthon, Avant and SOME versions / installations of Firefox. This has baffled me greatly. Firefox has been my browser of choice for a couple of years now. I have Firefox 5 and 9 at home, on Win7 64 bit machines. And everything returns as "undefined" on these two machines. The Win XP 32 bit / Firefox on the machines at school render this homework properly. This leads me to believe that the 64bit OS - Firefox combination is the problem.
Here's my code:
Register.asp
<form name="frmLogon" id="frmLogon" method="post" action="session.asp">
<h3>Logon</h3>
<label for="txtUserName">
Username:
<input type="text" name="txtUserName" maxlength="20" />
</label>
<br /><br />
<label for="txtPassword">
Password:
<input type="text" name="txtPassword" maxlength="20" />
</label>
<input type="hidden" name="hidSessionID" value="Session.SessionID"/>
<br /><br />
<center>
<input type="submit" value="Submit" name="btnSubmit"/>
<input type="reset" value="Reset" name="btnReset" />
</center>
</form>
</body>
Session.asp
<body>
<%
// Populate the cookie
Response.Cookies("registration")("UserName") = Request.Form("txtUserName");
Response.Cookies("registration")("Password") = Request.Form("txtPassword");
Response.Cookies("registration")("SessionID") = Session.SessionID;
Response.Cookies("registration")("Date") = Date();
Response.Cookies("registration")("Referer") = Request.ServerVariables("HTTP_REFERER");
Response.Cookies("registration")("RemoteIP") = Request.ServerVariables("REMOTE_ADDR");
// script required to set expiration date. (Not shown in textbook or sample code...)
var dtmDate;
dtmDate = new Date()
intMonth = dtmDate.getMonth() + 1
dtmDate.setDate(dtmDate.getDate() + 7)
strExpireDate = intMonth + "/" + dtmDate.getDate() + "/" + dtmDate.getFullYear()
Response.Cookies("registration").Expires = strExpireDate
Response.Redirect("Display.asp");
%>
</body>
Display.asp
<body>
<%
Break();
Response.write("<font color='blue'>The cookies keys and values:</font>");
Break();
Response.write("UserName: " + (Request.cookies("registration")("UserName")));
Break();
Response.write("Password: " + (Request.cookies("registration")("Password")));
Break();
Response.write("SessionID: " + (Request.cookies("registration")("SessionID")));
Break();
Response.write("Date: " + (Request.cookies("registration")("Date")));
Break();
Response.write("Referer: " + (Request.cookies("registration")("Referer")));
Break();
Response.write("RemoteIP: " + (Request.cookies("registration")("RemoteIP")));
Break();
Response.write("<hr />");
Break();
// Assign the cookie values to Session variables
Session("UserName") = Request.Cookies("registration")("UserName")
Session("Password") = Request.Cookies("registration")("Password")
Session("SessionID") = Request.Cookies("registration")("SessionID")
Session("Date") = Request.Cookies("registration")("Date")
Session("Referer") = Request.Cookies("registration")("Referer")
Session("RemoteIP") = Request.Cookies("registration")("RemoteIP")
// Display the session variables populated from the cookie.
Response.write("<font color='blue'>The session variables, populated by the cookies keys and values:</font>");
Break();
Response.write("UserName: " + Session("UserName"))
Break();
Response.write("Password: " + Session("Password"))
Break();
Response.write("SessionID: " + Session("SessionID"))
Break();
Response.write("Date: " + Session("Date"))
Break();
Response.write("Referer: " + Session("Referer"))
Break();
Response.write("Remote IP: " + Session("RemoteIP"))
Break();
Response.write("<hr />");
Break();
// Display the session variables populated from the cookie.
Response.write("<font color='blue'>The unformatted output of the 'Response.Write(Request.ServerVariables('HTTP_COOKIE'))' command:</font>");
Break();
Response.Write(Request.ServerVariables("HTTP_COOKIE"))
function Break()
{
Response.write("<br></br>")
}
%>
</body>
Can anyone explain why this entire exercise returns "undefined" variables only in Firefox on Win 7 64 bit?
First, WHY are you writing that all to cookie? Why not write that all directly to session. Cookies can provide security risk in the username and password later. I think it would be better to set all the session variables in "session.asp", but I guess that may be personal...
Back to your question, it is most likely that "Cookies" are disabled. Click here to learn about enabling cookies in firefox.

Retrieve Campaigns Microsoft Dynamic CRM 3.0

does anybody knows how to get (programmatically - C#) the list (and details) of campaigns on Microsoft CRM 3.0 (using the webservice CRM Service) ??
Any help or documentation link would be appreciated.
Thanks in advance.
If somebody is interested, I found out how to get campaigns from Microsoft CRM 3.0 using the webservice. Here is the code.
fetchFilter += #"<fetch mapping='logical'>";
fetchFilter += #"<entity name='campaign'><all-attributes/>";
fetchFilter += #"<link-entity name='systemuser' to='owninguser'>";
fetchFilter += #"<filter type='and'>";
fetchFilter += #"<condition attribute='firstname' operator='eq' value='" + firstName + "' />";
fetchFilter += #"<condition attribute='lastname' operator='eq' value='" + lastName + "' />";
fetchFilter += #"</filter>";
fetchFilter += #"</link-entity>";
fetchFilter += #"</entity>";
fetchFilter += #"</fetch>";
XmlDocument xmldoc = new XmlDocument();
xmldoc.LoadXml(CrmWebService.Fetch(fetchFilter));
Hope it will be useful for somebody.
Bye.

Resources