Reputation: 158
Good afternoon. I am running into a REALLY wierd issue trying to change a datagrid, and google hasn't been any luck. I am using the below javascripts to set the fetch and layout of a subgrid called "Opp_Prods".
function timeOutReassignFilter()
{
console.log("About to setTimeout");
setTimeout(SetProductView, 1000);
console.log("Set TimeOut");
}
function SetProductView()
{
try
{
var accountId = Xrm.Page.data.entity.getId();
var viewId = '{00000000-0000-0000-0000-000000000001}';
var entityName = "opportunityproduct";
var viewDisplayName = "Associated Opportunity Products View";
console.log("About to set fetchxml: " + accountId);
var fetchXml = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>" +
"<entity name='opportunityproduct'>" +
"<attribute name='productid' />" +
"<attribute name='productdescription' />" +
"<attribute name='priceperunit' />" +
"<attribute name='quantity' />" +
"<attribute name='new_serialnumber' />" +
"<attribute name='extendedamount' />" +
"<attribute name='opportunityproductid' />" +
"<order attribute='productid' descending='false' />" +
"<link-entity name='opportunity' from='opportunityid' to='opportunityid' alias='ac'>" +
"<filter type='and'>" +
"<condition attribute='parentaccountid' operator='eq' value='" + accountId + "' />" + //uiname='Test Account'
"</filter>" +
"</link-entity>" +
"</entity>" +
"</fetch>";
console.log("About to set layoutXml");
var layoutXml = "<grid name='Opp_Prods' object='1' jump='productid' select='1' icon='1' preview='1'>" +
"<row name='result' id='myproductid'>" +
"<cell name='productdescription' width='150' />" +
"<cell name='productid' width='150' />" +
"<cell name='priceperunit' width='150' />" +
"<cell name='quantity' width='150' />" +
"<cell name='extendedamount' width='150' />" +
"<cell name='new_serialnumber' width='150' />" +
"<cell name='opportunityproductid' width='150' />" +
"</row>" +
"</grid>";
console.log("About to set Control by adding custom view.");
// Xrm.Page.getControl("opp_prods").addCustomView(viewId, entityName, viewDisplayName, fetchXml, layoutXml, true);
document.getElementById("Opp_Prods").control.SetParameter("fetchXML", fetchXml);
document.getElementById("Opp_Prods").control.SetParameter("layoutXML", layoutXml);
Xrm.Page.ui.controls.get("Opp_Prods").refresh();
console.log("Custom View Added.");
}
catch(err)
{
console.log(err);
}
}
When the form loads, it's throwing the following error:
Unhandled Exception: System.ServiceModel.FaultException`1[[Microsoft.Xrm.Sdk.OrganizationServiceFault, Microsoft.Xrm.Sdk, Version=7.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]: System.Xml.XmlException: Microsoft Dynamics CRM has experienced an error. Reference number for administrators or support: #E63BFD86Detail:
-2147220970 System.Xml.XmlException: Microsoft Dynamics CRM has experienced an error. Reference number for administrators or support:E63BFD86 2015-08-25T16:13:21.2028543Z
<ErrorCode>-2147220970</ErrorCode> <ErrorDetails xmlns:d3p1="http://schemas.datacontract.org/2004/07/System.Collections.Generic"
/> System.InvalidCastException: Microsoft Dynamics CRM has experienced an error. Reference number for administrators or support:
F2D68509
<Timestamp>2015-08-25T16:13:21.2028543Z</Timestamp> <InnerFault i:nil="true" /> <TraceText i:nil="true" /> </InnerFault> <TraceText i:nil="true" /> </OrganizationServiceFault>
And here's the full trace from our CRM trace logs:
[2015-08-25 11:24:37.314] Process: w3wp |Organization:f6d279c3-1548-e511-80bd-00155d001302 |Thread: 118 |Category: Application |User: 00000000-0000-0000-0000-000000000000 |Level: Error |ReqId: 021d486e-5560-4f4e-a87a-a138ee9f8f3f | ErrorInformation.LogError ilOffset = 0x17
MSCRM Error Report: -------------------------------------------------------------------------------------------------------- Error: System.InvalidCastException: Unable to cast object of type 'System.DBNull' to type 'Microsoft.Xrm.Sdk.OptionSetValue'. at Microsoft.Crm.Application.Controls.Grid.UI.PropertyTemplatePropertiesConfigurationColumn.BindData(WebControl parentControl, IRowDataSource rowData) at System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) at System.Web.UI.Control.DataBindChildren() at System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) at System.Web.UI.WebControls.GridView.CreateRow(Int32 rowIndex, Int32 dataSourceIndex, DataControlRowType rowType, DataControlRowState rowState, Boolean dataBind, Object dataItem, DataControlField[] fields, TableRowCollection rows, PagedDataSource pagedDataSource)
at System.Web.UI.WebControls.GridView.CreateChildControls(IEnumerable dataSource, Boolean dataBinding) at System.Web.UI.WebControls.CompositeDataBoundControl.PerformDataBinding(IEnumerable data) at System.Web.UI.WebControls.GridView.PerformDataBinding(IEnumerable data) at System.Web.UI.WebControls.DataBoundControl.OnDataSourceViewSelectCallback(IEnumerable data) at System.Web.UI.WebControls.DataBoundControl.PerformSelect() at Microsoft.Crm.Application.Controls.Grid.UI.LayoutProviderGridList.RenderGridData(HtmlTextWriter output) at Microsoft.Crm.Application.Controls.Grid.UI.LayoutProvider.Render(HtmlTextWriter output) at Microsoft.Crm.Application.Controls.GridUIProvider.Render(HtmlTextWriter output) at Microsoft.Crm.Core.Application.WebServices.AppGridWebServiceHandler.GetRefreshResponseHtml(IGridUIProvider uiProvider, StringBuilder sbTemp) at Microsoft.Crm.Core.Application.WebServices.AppGridWebServiceHandler.Refresh(String gridXml, StringBuilder sbXml, StringBuilder sbHtml, Boolean returnJsonData) at Microsoft.Crm.Core.Application.WebServices.AppGridWebServiceHandler.ProcessRequestInternal(HttpContext context)Error Message: System.InvalidCastException: Unable to cast object of type 'System.DBNull' to type 'Microsoft.Xrm.Sdk.OptionSetValue'. at Microsoft.Crm.Application.Controls.Grid.UI.PropertyTemplatePropertiesConfigurationColumn.BindData(WebControl parentControl, IRowDataSource rowData) at System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) at System.Web.UI.Control.DataBindChildren() at System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) at System.Web.UI.WebControls.GridView.CreateRow(Int32 rowIndex, Int32 dataSourceIndex, DataControlRowType rowType, DataControlRowState rowState, Boolean dataBind, Object dataItem, DataControlField[] fields, TableRowCollection rows, PagedDataSource pagedDataSource)
at System.Web.UI.WebControls.GridView.CreateChildControls(IEnumerable dataSource, Boolean dataBinding) at System.Web.UI.WebControls.CompositeDataBoundControl.PerformDataBinding(IEnumerable data) at System.Web.UI.WebControls.GridView.PerformDataBinding(IEnumerable data) at System.Web.UI.WebControls.DataBoundControl.OnDataSourceViewSelectCallback(IEnumerable data) at System.Web.UI.WebControls.DataBoundControl.PerformSelect() at Microsoft.Crm.Application.Controls.Grid.UI.LayoutProviderGridList.RenderGridData(HtmlTextWriter output) at Microsoft.Crm.Application.Controls.Grid.UI.LayoutProvider.Render(HtmlTextWriter output) at Microsoft.Crm.Application.Controls.GridUIProvider.Render(HtmlTextWriter output) at Microsoft.Crm.Core.Application.WebServices.AppGridWebServiceHandler.GetRefreshResponseHtml(IGridUIProvider uiProvider, StringBuilder sbTemp) at Microsoft.Crm.Core.Application.WebServices.AppGridWebServiceHandler.Refresh(String gridXml, StringBuilder sbXml, StringBuilder sbHtml, Boolean returnJsonData) at Microsoft.Crm.Core.Application.WebServices.AppGridWebServiceHandler.ProcessRequestInternal(HttpContext context)Source File: Not available
Line Number: Not available
Request URL: https://manufacturingdemo.crm2015.cloudappsonline.net/AppWebServices/AppGridWebService.ashx?operation=Refresh
Stack Trace Info: [InvalidCastException: Unable to cast object of type 'System.DBNull' to type 'Microsoft.Xrm.Sdk.OptionSetValue'.] at Microsoft.Crm.Application.Controls.Grid.UI.PropertyTemplatePropertiesConfigurationColumn.BindData(WebControl parentControl, IRowDataSource rowData) at System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) at System.Web.UI.Control.DataBindChildren() at System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) at System.Web.UI.WebControls.GridView.CreateRow(Int32 rowIndex, Int32 dataSourceIndex, DataControlRowType rowType, DataControlRowState rowState, Boolean dataBind, Object dataItem, DataControlField[] fields, TableRowCollection rows, PagedDataSource pagedDataSource)
at System.Web.UI.WebControls.GridView.CreateChildControls(IEnumerable dataSource, Boolean dataBinding) at System.Web.UI.WebControls.CompositeDataBoundControl.PerformDataBinding(IEnumerable data) at System.Web.UI.WebControls.GridView.PerformDataBinding(IEnumerable data) at System.Web.UI.WebControls.DataBoundControl.OnDataSourceViewSelectCallback(IEnumerable data) at System.Web.UI.WebControls.DataBoundControl.PerformSelect() at Microsoft.Crm.Application.Controls.Grid.UI.LayoutProviderGridList.RenderGridData(HtmlTextWriter output) at Microsoft.Crm.Application.Controls.Grid.UI.LayoutProvider.Render(HtmlTextWriter output) at Microsoft.Crm.Application.Controls.GridUIProvider.Render(HtmlTextWriter output) at Microsoft.Crm.Core.Application.WebServices.AppGridWebServiceHandler.GetRefreshResponseHtml(IGridUIProvider uiProvider, StringBuilder sbTemp) at Microsoft.Crm.Core.Application.WebServices.AppGridWebServiceHandler.Refresh(String gridXml, StringBuilder sbXml, StringBuilder sbHtml, Boolean returnJsonData) at Microsoft.Crm.Core.Application.WebServices.AppGridWebServiceHandler.ProcessRequestInternal(HttpContext context)[XmlException: System.InvalidCastException: Unable to cast object of type 'System.DBNull' to type 'Microsoft.Xrm.Sdk.OptionSetValue'. at Microsoft.Crm.Application.Controls.Grid.UI.PropertyTemplatePropertiesConfigurationColumn.BindData(WebControl parentControl, IRowDataSource rowData) at System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) at System.Web.UI.Control.DataBindChildren() at System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) at System.Web.UI.WebControls.GridView.CreateRow(Int32 rowIndex, Int32 dataSourceIndex, DataControlRowType rowType, DataControlRowState rowState, Boolean dataBind, Object dataItem, DataControlField[] fields, TableRowCollection rows, PagedDataSource pagedDataSource)
at System.Web.UI.WebControls.GridView.CreateChildControls(IEnumerable dataSource, Boolean dataBinding) at System.Web.UI.WebControls.CompositeDataBoundControl.PerformDataBinding(IEnumerable data) at System.Web.UI.WebControls.GridView.PerformDataBinding(IEnumerable data) at System.Web.UI.WebControls.DataBoundControl.OnDataSourceViewSelectCallback(IEnumerable data) at System.Web.UI.WebControls.DataBoundControl.PerformSelect() at Microsoft.Crm.Application.Controls.Grid.UI.LayoutProviderGridList.RenderGridData(HtmlTextWriter output) at Microsoft.Crm.Application.Controls.Grid.UI.LayoutProvider.Render(HtmlTextWriter output) at Microsoft.Crm.Application.Controls.GridUIProvider.Render(HtmlTextWriter output) at Microsoft.Crm.Core.Application.WebServices.AppGridWebServiceHandler.GetRefreshResponseHtml(IGridUIProvider uiProvider, StringBuilder sbTemp) at Microsoft.Crm.Core.Application.WebServices.AppGridWebServiceHandler.Refresh(String gridXml, StringBuilder sbXml, StringBuilder sbHtml, Boolean returnJsonData) at Microsoft.Crm.Core.Application.WebServices.AppGridWebServiceHandler.ProcessRequestInternal(HttpContext context)] at Microsoft.Crm.Core.Application.WebServices.AppGridWebServiceHandler.ProcessRequestInternal(HttpContext context) at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
I am completely baffled, and help you guys can offer would be tremendously appreciated. The most troubling thing about this is that none of the fields I'm fetching are an option set, so what's going on here? Thank you.
Upvotes: 2
Views: 1593
Reputation: 17562
So I think your approach is a bit off.
You are using unsupported JavaScript for starters document.getElementById
which you should never expect to work.
The error Unable to cast object of type 'System.DBNull' to type 'Microsoft.Xrm.Sdk.OptionSetValue'
is a bit of an odd one. Looks like you can have set a DBNull
value somehow which CRM isn't expecting.
There are supported methods for playing with the sub grid which will allow you to change the view, however they look quite different to your approach. See Write scripts for subgrids. For example:
var ContactsIFollow = {
entityType: 1039, // SavedQuery
id:"{3A282DA1-5D90-E011-95AE-00155D9CFA02}",
name: "Contacts I Follow"
}
Xrm.Page.getControl("Contacts").getViewSelector().setCurrentView(ContactsIFollow);
For sub grids it looks like you are only able to set an already existing view by Id, as opposed to your approach of changing the Layout and Fetch XML.
As a side, the lookup control does support setting the Layout and Fetch XML using addCustomView. However the two controls - sub grid, & lookup are quite different and should not be confused.
Upvotes: 1