I know how to modify the FetchXml of the subgrid. I'm attempting to dynamically change a subgrid based on selections from optionsets with JS. Based on the optionsets, the subgrid will need to be able to display different entities (not at the same time).
Example: The subgrid is currently showing Accounts with a specific relationship type. An optionset changes and now the subgrid should show Leads whose first name is John.
The error I'm receiving is "Entity Name specified in FetchXml does not match the entity name in the EntityExpression"
I feed the below fetch into the grid. It's just a multi-value search. rc_entitylist contains all entities in the system. rc_attributelist contains all the fields for the selected entity. The user selects an entity, selects a field to search, enters search criteria (one value per line) and then it populates the subgrid accordingly.
function runSearch() {
var entityname = Xrm.Page.getAttribute("rc_entitylist").getText();
var sgrid = "searchResults";
var fetchXml = '<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false">'+
'<entity name="' + entityname + '">'+
'<all-attributes />' +
'<filter type="and">'+
'<filter type="or">';
var textBoxLines = document.getElementById("rc_searchcriteria").innerText;
var attributename = Xrm.Page.getAttribute("rc_attributelist").getText();
var lines = textBoxLines.split(/\n/);
for(var i=0;i < lines.length; i++){
fetchXml = fetchXml + '<condition attribute="' + attributename + '" operator="eq" value="'+ lines[i] +'" />';
}
fetchXml = fetchXml + '</filter>'+
'</filter>'+
'</entity>'+
'</fetch>';
updateXml(sgrid, fetchXml, entityname);
}
function updateXml(grid, xmlfield, entityname) {
try {
var g = document.getElementById(grid).control;
g.setParameter("fetchXml", xmlfield);
} catch (e) { }
// Refresh the grid
document.getElementById(grid).control.refresh();
}
Have you thought about adding multiple subgrids to the form, and hiding/showing them based on the on-change event of the optionset?
Related
I have a sub-grid dynamics 365 crm named competitors I have to get data from that sub-grid and print it into alert. I have searched in the net but every solution I get from there when I used is throwing error as deprecated method. How can I get the sub-grid data in dynamics 365 application using JavaScript. Can anyone provide sample code for that.
Thanks in advance
Here is below code I tried in one of my Instance. Considering you want alert on Opportunity entity and that too onload of a form.
Use Debugger and you will get the data.
function onLoad(executionContext){
debugger;
var formContext = executionContext.getFormContext();
var formType= formContext.ui.getFormType();
if(formType && formType!==1 && formContext.data.entity.getId()){
retreiveOppCompRecords(formContext.data.entity.getId().replace(/[{}]/g, "")).then(
function success(result) {
if(result.entities.length > 0){
for(i=0;i<result.entities.length;i++){
}
}
},
function (error) {
var alertStrings = {
confirmButtonLabel: "OK",
text: 'Failed at Function: enableDisableExpiryDate with error: ' + error.message
};
var alertOptions = {
height: 250,
width: 450
};
Xrm.Navigation.openAlertDialog(alertStrings, alertOptions);
}
);
}
}
function retreiveOppCompRecords(recordId){
var fetchxml = ['<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false">',
'<entity name="opportunity" >',
'<attribute name="name" />',
'<filter type="and" >',
'<condition attribute="opportunityid" operator="eq" value="' + recordId + '" />',
'</filter>',
'<link-entity name="opportunitycompetitors" from="opportunityid" to="opportunityid" alias="OppCompetitor" intersect="true" >',
'<link-entity name="competitor" from="competitorid" to="competitorid" link-type="inner" alias="Competitor" >',
'<attribute name="websiteurl" alias="CompetitorWebsite" />',
'<attribute name="name" alias="CompetitoName" />',
'</link-entity>',
'</link-entity>',
'</entity>',
'</fetch>'].join("");
fetchxml = "?fetchXml=" + encodeURIComponent(fetchxml);
return Xrm.WebApi.retrieveMultipleRecords("opportunity", fetchxml);
}
As AnkUser has eluded to you need to retrieve the associated records from your subgrid adding in the <attribute name=''> tags as needed for the columns you need.
Remember a sub-grid is simply a view of data, usually, associated with the given record.
What specifically are you trying to retrieve from the subgrid?
I found my answer already - I have added an onload event to subgrid via JavaScript and retrieved data using Xrm.Page.getControl(“entityname”).getGrid().
I have HTML table. I get data from Firebase and append that data to my HTML table, with classes.
I'm trying to figure out how to select that appended data on my HTML and update values, because my values changes by time (I do some math with time).
I know the way to select using on.('click'), but I would like to select it and update it without any click events.
var frequency = snapshot.val().frequency;
var recordKey = snapshot.key;
var minsAway = frequency - (firstCurrentDiff % frequency);
var nextArrival = moment().add(minsAway, "minutes").format("HH:mm")
var row = $("<tr>").attr("class", recordKey);
row.appendTo("#tableBody");
$("<td>" + frequency + "</td>").appendTo(row);
$("<td>" + nextArrival + "</td>").appendTo(row);
$('<td class="mins-away">' + minsAway + "</td>").appendTo(row);
If i get what you need, after append, you can get it with :last
row.appendTo("#tableBody");
$myrow = $("#tableBody tr:last");
And then, for ex, refer to each td or find specific one:
$td_mins_away = $myrow.find('td.mins-away');
I've tried customizing Email's regardingobjectid lookup dropdown, using the following code:
var regardingobjectid = Xrm.Page.getControl("regardingobjectid");
/* The value of viewId is a dummy value,
and only needs to be unique among the other available views for the lookup. */
var viewId = '{00000000-0000-0000-0000-000000000001}';
var entityName = 'lu_service';
var viewDisplayName = 'service - custom view';
var fetchXml =
'<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="true" >' +
'<entity name="lu_service">' +
'<attribute name="lu_serviceid" />' +
'<attribute name="lu_name" />' +
'<attribute name="createdon" />' +
'<order attribute="lu_name" descending="false" />' +
'</entity>' +
'</fetch>';
var lookupService = new RemoteCommand("LookupService", "RetrieveTypeCode");
lookupService.SetParameter("entityName", "lu_service");
var result = lookupService.Execute();
var objectTypeCode = result.ReturnValue;
var layoutXml =
'<grid name="resultset" object="' + objectTypeCode + '" jump="lu_name" select="1" icon="1" preview="1">' +
'<row name="lu_service" id="lu_serviceid">' +
'<cell name="lu_name" width="300" />' +
'<cell name="createdon" width="125" />' +
'</row>' +
'</grid>';
regardingobjectid.addCustomView(viewId, entityName, viewDisplayName, fetchXml, layoutXml, true);
I thought that this code should do two things:
1. Customize the lookup dropdown, i.e., display the records of the required type (in my example: lu_service) on the dropdown displayed when clicking the lookup field.
2. Add a custom view onto the window opened when clicking the "Look Up More Records" link (listed at the end of the lookup dropdown).
The result is that 1 doesn't work, and 2 works.
My question is: Should've 1 worked? If not, is it possible to achieve this?
For point #1 in 2015 version, you have to use addPreSearch and addCustomFilter to filter out the unwanted entities in the dropdown list. This is the only supported way/workaround. Read more
For example, the below filter will show lu_service & remove any account from regardingobjectid lookup. Trick is account will not have null accountid.
var serviceFilter = "<filter type='and'><condition attribute='lu_serviceid' operator='not-null' /></filter>";
//remove accounts
var accountFilter = "<filter type='and'><condition attribute='accountid' operator='null' /></filter>";
Xrm.Page.getControl('regardingobjectid').addCustomFilter(serviceFilter, "lu_service");
Xrm.Page.getControl('regardingobjectid').addCustomFilter(accountFilter, "account");
Before I begin, I should mention I am using Javascript but I'm not using JQuery.
I have a function which obtains data from a site and displays it in an HTML table.
I would like to add a checkbox to each row, and find if each one has been checked or not later (i.e. when a button is clicked), outside of the function that creates the table.
The reason for this is that the function that makes the table only runs once and can't check if the box is checked or not (the user hasn't had a chance to check any yet!).
Each checkbox relates to other data displayed on the same row, which I can access outside of _cb_findItemsAdvanced(root) by declaring the 'items' variable before the function begins. However, I can't seem to do this for checkboxes.
I can add normal checkboxes to the table with:
"<input type=checkbox...".
However, I can't seem to access them from outside of the function that makes the table (and calls for the data). I've tried:
document.form1.sharedCheckboxName
It didn't seem to work.
I have tried everything, from creating a global checkbox array and trying to specify
" + checkbox[i] + "
instead of
"<input type=checkbox...",
but it didn't work. I know my current code has just specified a variable of type checkbox, rather than what I want which is to populate the table with my existing, global, array of checkboxes.
Any help would be greatly appreciated, as I am lost! I hope you're not, after reading that! :-)
Here is my code:
var items;
var checkbox = [];
function _cb_findItemsAdvanced(root)
{
items = root.findItemsAdvancedResponse[0].searchResult[0].item || [];
var html = [];
html.push('<table width="100%" border="0" cellspacing="0" cellpadding="3"><form name="form1"><tbody>');
for (var i = 0; i < items.length; ++i)
{
var item = items[i];
var title = item.title;
var pic = item.galleryURL;
var viewitem = item.viewItemURL;
checkbox[i] = document.createElement('input');
checkbox[i].type = "checkbox";
checkbox[i].name = "name";
checkbox[i].value = "value";
checkbox[i].id = "id" + i;
if (null != title && null != viewitem)
{
html.push('<tr><td>' + '<img src="' + pic + '" border="0">' + '</td>' +
'<td>' + title + '</td>' + '<td> <input type = "' + checkbox[i].type + '" + </t></tr>');
}
}
html.push('</tbody></table>');
document.getElementById("results").innerHTML = html.join("");
}
if (checkbox[0].checked)
{
alert("HI"); //but nothing happens
}
since you are using html string forget about the checkboxes array.
your form should wrap the table not the other way around.
give your form an id
<form id="form1">
get the form and find all checkboxes
function findCheckedItems() {
var checkedItems = [];
var form = getElementById('form1');
var inputs = form.getElementsByTagName("input");
var checkboxIndex = 0;
for (var i = 0; i < inputs.length; i++) {
if (inputs[i].type.toLowerCase() === 'checkbox') {
if (inputs[i].checked) {
var data = item[checkboxIndex];
checkedItems.push(data);
// do whatever you like with the data
}
checkboxIndex++;
}
}
return checkedItems;
}
i search a solution to add a specific filter on the new lookup quickfind.
the problem is specific on the customerid lookup type, because this used the "client" types who included the account and contact on the same lookup (this is the new multi-entity lookup)
i get on this lookup account and contact, and want to filter just the contact who are from a specific account.
i try another way to change it is to change the html object but without success.
here is the html data of the specific lookup.
the lookuptypesnames and createpermissiondictionary contains account and contact, if i change the lookuptype=1 that give me anly the contact.
then
i search a native way to change the customerid lookup on a specific entity (just on contact ) , dont want to used jquery function.
This is what I've done to set up the Customer lookup to show only Contact records.
function Form_OnLoad()
...
preFilterLookup();
..
}
function preFilterLookup() {
Xrm.Page.getControl("customerid").addPreSearch(addLookupFilter);
}
function addLookupFilter() {
document.getElementById("customerid_i").setAttribute("lookuptypenames", "contact:2:Contact");
document.getElementById("customerid_i").setAttribute("lookuptypes", "2");
var account = Xrm.Page.getAttribute("aux_account").getValue();
if (account != null) {
var filter = "<filter type='and'>" + "<condition attribute='parentcustomerid' operator='eq' value='" + account[0].id + "' /></filter>";
Xrm.Page.getControl("customerid").addCustomFilter(filter);
}
You should use setLookupTypes.
Something like this:
var owner = Xrm.Page.getAttribute("ownerid").getLookupDataAttribute();
owner.setLookupTypes(["systemuser"]);
if the account control is a lookup then your fetchXml should be
fetchXml = "<filter type='and'><condition attribute='parentcustumerid' operator='eq' uitype='contact' value='" + account[0].id + "' /></filter>";