locked
Working with Link Entity RRS feed

  • Question

  • Hi,

    I have a custom field in "Product" entity and call it "Product Group"(new_productgroup).
    I also have another custom N:1 relationship between "Product" and "Competitor" with the name "new_competitor_product" and relationship attribute name is "new_competitorid".

    In the "Phone Call" entity I need to fetch all "Competitor"s that sale "product"s with the 'A' "Product Group" and filter my "competitor" lookup to its records.

    I wrote the following code with try and error and without understanding the background concept and it does not work.

    	var fetchStr = "<fetch mapping='logical'>" +
    			"  <entity name='competitor'>" +
    			"    <all-attributes />" +
    			"    <link-entity name='new_competitor_product' from='new_competitorid' to='new_competitorid' intersect='true' visible='false'>" + 
    			"    <link-entity name='product' from='productid' to='productid' alias='aa'>" + 
    			"    <all-attributes />" +
    			"		 <filter>" +
    			"      <condition attribute='new_productgroup' operator='eq' value='1' />" +
    			"    </filter>" +
    			"    </link-entity>" +
    			"  </entity>" +
    			"</fetch> ";
    	crmForm.all.new_competitorid.lookupbrowse = 1; 
    	crmForm.all.new_competitorid.AddParam("search", fetchStr);
    

    Please guide me to edit it...

    Sunday, August 19, 2012 8:01 AM

Answers

  • Hi Soroosh,

    You don't need the link to new_competitor_product unless you are using a N:N relationship. If you only have a N:1 your fetchxml would be something like:

    <fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="true">
      <entity name="competitor">
        <all-attributes />
        <order attribute="name" descending="false" />
        <link-entity name="product" from="new_competitorid" to="competitorid" alias="aa">
          <filter type="and">
            <condition attribute="new_productgroup" operator="eq" value="1" />
          </filter>
        </link-entity>
      </entity>
    </fetch>

    hth,

    Scott


    Scott Durow
    Read my blog: www.develop1.net/public
    If this post answers your question, please click "Mark As Answer" on the post and "Mark as Helpful"

    Sunday, August 19, 2012 9:09 AM
    Answerer

All replies

  • Hi Soroosh,

    You don't need the link to new_competitor_product unless you are using a N:N relationship. If you only have a N:1 your fetchxml would be something like:

    <fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="true">
      <entity name="competitor">
        <all-attributes />
        <order attribute="name" descending="false" />
        <link-entity name="product" from="new_competitorid" to="competitorid" alias="aa">
          <filter type="and">
            <condition attribute="new_productgroup" operator="eq" value="1" />
          </filter>
        </link-entity>
      </entity>
    </fetch>

    hth,

    Scott


    Scott Durow
    Read my blog: www.develop1.net/public
    If this post answers your question, please click "Mark As Answer" on the post and "Mark as Helpful"

    Sunday, August 19, 2012 9:09 AM
    Answerer
  • Thank you Scott 

    It's work...

    Monday, August 20, 2012 9:30 AM