CRM 2011: Problem with script to create runtime view
-
2012년 6월 25일 월요일 오후 5:51
Hi all, I have developed a java script to create a runtime lookup view for the product entity in a custom child entity for the quote entity.
I need to filter the products to display only the products that has been selected in quote products that belongs to the same quote.
I have created the view with advanced find and using a specific quote, then I have modified it to work dynamically with any record under the quote. when opening the lookup dialog a generic exception is thrown: Try this action again. If the problem continues,...
Below is my code:
/// <reference path="XrmPageTemplate.js" /> function CreateExistingProductsView() { quote = Xrm.Page.getAttribute( "new_quoteid" ); if ( quote.getValue() != null ) { quoteId = quote.getValue()[0].id; quoteName = quote.getValue()[0].name; //build fetchxml var viewId = "{00000000-0000-0000-0000-000000000001}"; var entityName = "product"; var viewDisplayName = "Existing Products"; var fetchXml = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='true'>"+ +"<entity name='product'>"+ +"<attribute name='name' />"+ +"<attribute name='productnumber' />"+ +"<attribute name='subjectid' />"+ +"<attribute name='statecode' />"+ +"<attribute name='new_supplierclassificationid' />"+ +"<attribute name='new_offeringownerid' />"+ +"<attribute name='new_qualifiedforincentive' />"+ +"<attribute name='new_defaultsupplierid' />"+ +"<attribute name='productid' />"+ +"<order attribute='productnumber' descending='false' />"+ +"<link-entity name='quotedetail' from='productid' to='new_productid' alias='aa'>"+ +"<link-entity name='quote' from='quoteid' to='quoteid' alias='ab'>"+ +"<filter type='and'>"+ +"<condition attribute='quoteid' operator='eq' uiname='"+quoteName+"' uitype='"+quote+"' value='"+quoteId+"' />" + +"</filter>"+ +"</link-entity>"+ +"</link-entity>"+ +"</entity>"+ +"</fetch>"; //build grid layout var layoutXml = "<grid name='resultset' object='1024' jump='name' select='1' preview='1' icon='1'>" + +"<row name='result' id='productid'>" + +"<cell name='productnumber' width='100' />" + +"<cell name='name' width='300' />" + +"<cell name='subjectid' width='300' />" + +"<cell name='new_offeringownerid' width='100' />" + +"<cell name='new_defaultsupplierid' width='100' />" + +"<cell name='new_supplierclassificationid' width='300' />" + +"<cell name='statecode' width='100' />" + +"<cell name='new_qualifiedforincentive' width='100' />" + +"</row>" + +"</grid>"; //add new view view Xrm.Page.getControl( "new_productid" ).addCustomView( viewId, entityName, viewDisplayName, fetchXml, layoutXml, true ); } }Please advise..
Thanks and best regards..
모든 응답
-
2012년 6월 26일 화요일 오전 8:36
Have you tried to debug the code using internet explorer debugger(f12)?
Are you sure that you a getting the right quoteId? I normally retrieve data from a lookup like this:
var lookupItem = new Array(); lookupItem = Xrm.Page.getAttribute("new_quoteid").getValue(); if (lookupItem != null) { var name = lookupItem[0].name; var guid = lookupItem[0].id; var entType = lookupItem[0].entityType; }
- 편집됨 Casper Schau 2012년 6월 26일 화요일 오전 8:36
-
2012년 6월 26일 화요일 오전 9:39
Have you tried to debug the code using internet explorer debugger(f12)?
I normally retrieve data from a lookup like this:
var lookupItem = new Array(); lookupItem = Xrm.Page.getAttribute("new_quoteid").getValue(); if (lookupItem != null) { var name = lookupItem[0].name; var guid = lookupItem[0].id; var entType = lookupItem[0].entityType; }I think this is similar to what I've done:
quote = Xrm.Page.getAttribute( "new_quoteid" ); if ( quote.getValue() != null ) { quoteId = quote.getValue()[0].id; quoteName = quote.getValue()[0].name;Except that I didn't retrieve the entityType from lookup, however I will try to debug the code and will get back to you
Thanks and best regards..
-
2012년 6월 26일 화요일 오전 9:49I tried to debug the code with no luck, please advise...
-
2012년 6월 27일 수요일 오전 7:04
-
2012년 6월 29일 금요일 오후 1:51Are you sure the value of distinct in fetchXml should be true?
-
2012년 6월 29일 금요일 오후 4:40
Hi,
This is not correct :- [quote = Xrm.Page.getAttribute( "new_quoteid" );] this should be entity type
Please update the follwing line as below, you dont need 'uiname' and 'uitype' so you can safely remove it from the fetchXml+"<filter type='and'>"+
+"<condition attribute='quoteid' operator='eq' value='"+quoteId+"' />" +
+"</filter>"+Also make sure the lookup has the following properties set
addCustomView only works when the "Additional Properties" on the Lookup is set to the following
1). Customisation -> Entity -> Forms -> Main Form
2). Select the Lookup Attribute and open properties
a). Navigate to Additional Properties and make sure the following properties are set
*) Default View is Set to some view
*) View Selector SHOULD NOT BE SET TO Off for the code to work
Hope this helps. Amar
CRM Forum Guidance on how to Help Us Help You
-
2012년 7월 1일 일요일 오전 9:01
I have tried all the above with no luck, however I'm sure that the fetch Xml part is correct as it has been created using Advanced Find
Please advise..
- 편집됨 mo32 2012년 7월 1일 일요일 오전 9:04
-
2012년 7월 1일 일요일 오후 12:26
Hello Mostafa El Moatassem bellah:
First confusion that I have in your code is viewID.
Anyways, if you want you can use the approach that I am suggesting below. Its a sample code to fulfill your requirement.
After going through your requirement, I concluded that you want to create view with dynamic filter. Here I am providing the code for creating your custom view on run time and then passing the filters as per your requirement. In case of any confusion or query, feel free to contact me // Advanced Filtered Lookup function AdvancedFilteredLookup(lookupSchemaName, viewId, entityName, primaryKeyName, primaryFieldName, viewDisplayName, filterBy, orderBy, viewColumns) { var fetchXml = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>" + "<entity name='" + entityName + "'>" + "<attribute name='" + primaryFieldName + "' />" + "<order attribute='" + orderBy + "' descending='false' />" + "<filter type='and'>" + "<filter type='and'>"; for(var i=0; i< filterBy.length; i++) fetchXml += "<condition attribute='" + filterBy[i].SchemaName + "' operator='" + filterBy[i].Operator + "' value='" + filterBy[i].Value + "' />"; fetchXml += "</filter></filter></entity></fetch>"; var layoutXml = "<grid name='resultset' " + "object='1' " + "jump='name' " + "select='1' " + "icon='1' " + "preview='1'>" + "<row name='result' " + "id='" + primaryKeyName + "'>"; for(var i=0; i< viewColumns.length; i++) layoutXml += "<cell name='" + viewColumns[i].SchemaName + "' width='" + viewColumns[i].Width.toString() + "' />"; layoutXml += "</row></grid>"; try { var lookupControl = Xrm.Page.ui.controls.get(lookupSchemaName); lookupControl.addCustomView(viewId, entityName, viewDisplayName, fetchXml, layoutXml, true); } catch(err) { } }
Can follow this thread as it is same as yours LinkIf my suggestion helps you in solving your issue, kindly do me a great favor by marking it as correct answer. Thanks in advance "Saurabh Gupta, MS CRM 2011 Software Development Engineer"
- 답변으로 제안됨 SaurabhGupta_2160 2012년 7월 1일 일요일 오후 12:27