web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Add custom view

(0) ShareShare
ReportReport
Posted on by

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

I have the same question (0)
  • Suggested answer
    AbiRami Profile Picture
    516 on at

    Hi,

    May be because of the format. Copy the below format for fetchxml and layout.

    <fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'><entity name='new_projecttemplateitem'><attribute name='new_name' /><filter type='and'><condition attribute='new_projecttemplate' operator='eq' value='" + projectTemplateId + "' /></filter></entity></fetch>

    <grid name='resultset' object='1' jump='productid' select='1' icon='1' preview='1'><row name='result' id='new_projecttemplateitemid'><cell name='new_name' width='150' /><cell name='createdon' width='150' /></row></grid>

    Thanks

  • Verified answer
    Nour Profile Picture
    on at

    I was missing a space in my fetchXML./

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans