web
You’re offline. This is a read only version of the page.
close
Skip to main content
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)
  • Verified answer
    Nour Profile Picture
    on at
    RE: Add custom view

    I was missing a space in my fetchXML./

  • Suggested answer
    AbiRami Profile Picture
    516 on at
    RE: Add custom view

    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

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
Aric Levin - MVP Profile Picture

Aric Levin - MVP 2 Moderator

#1
HR-09070029-0 Profile Picture

HR-09070029-0 2

#3
MA-04060624-0 Profile Picture

MA-04060624-0 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans