Dear All,
I have written down the following code to be able to add a custom view for my lookup.
I have a custom entity called hardware quote product.
In the hardware quote product, I have 2 lookup fields: pricelist and product.
When I choose a certain pricelist, all the products that belong to this pricelist should appear in the product lookup like the built in quote product already existing in CRM.
When I am deploying the code on change of pricelist, seect the pricelist, and then press on product to choose a product, I am getting an error.
What is wrong in my code below? I searched the internet and found out that my requirement can only be done using addcustomview and not presearchlookup since I am searching for a related entity field.
Thank you.
function setCustomView() {
var lookupFieldObject = Xrm.Page.data.entity.attributes.get('edm_pricelist');
var pricelistid = lookupFieldObject.getValue()[0].id;
// add the randomly generated GUID for the view id
var viewId = '{00000000-0000-0000-0000-000000000001}';
//add the entity name
var entityName = "product";
// add the view display name
var viewDisplayName = "Product with Pricelist Lookup";
// fetch xml for filtered products
var fetchXml = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='true'>" +
" <entity name='product'>"+
"<attribute name='name' />"+
"<attribute name='productid'/>"+
// "<attribute name='productnumber'/>" +
// "<attribute name='description' />" +
// "<order attribute='productnumber' descending='false' />" +
"<link-entity name='productpricelevel' from='productid' to='productid' alias='aa'>"+"<filter type='and'>"+" <condition attribute='pricelevelid' operator='eq' '"+pricelistid+"'/>"+
"</filter>"+
"</link-entity>"+
"</entity>"+
"</fetch>";
var layoutXml = "<grid name='resultset' object='1' jump='productid' select='1' icon='1' preview='1'>" +
"<row name='result' id='productid'>"+
"<cell name='name' width='150' />"+
// "<cell name='createdon' width='150'/>" +
"</row>"+
"</grid>";
// add the custom view for the lookup field
Xrm.Page.getControl('edm_product').addCustomView(viewId, entityName, viewDisplayName, fetchXml, layoutXml, true);
}
*This post is locked for comments