Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Link of two lookups which are from different entities which don't have relationship between them

Posted on by Microsoft Employee

Basically I have 2 entities. for example B,C


In Entiy B I have one field called OfficerName(Lookup)

In Entity C I have one field called Advisor(lookup).


My question is if you select Advisor as XYZ it should auto populate in OfficerName same like XYZ only.


They don't have relationship between each entities

Version: MS Dynamics CRM 2016


I was struck in this situation can you help me

Thanks

*This post is locked for comments

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Link of two lookups which are from different entities which don't have relationship between them

    What about oncreate?

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Link of two lookups which are from different entities which don't have relationship between them

    can we create oncreate java-script function for same property???

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Link of two lookups which are from different entities which don't have relationship between them

    Yes Aric, it worked for me finally after many hurdles.

    Thanks for your suggestion

  • Suggested answer
    Aric Levin Profile Picture
    Aric Levin 30,188 on at
    RE: Link of two lookups which are from different entities which don't have relationship between them

    You can select the first entity, get the value from the lookup, and call a web api function using JavaScript to query the other entity for the same name. The query will return the Guid from the second entity, and you can call the setValue function of the second lookup attribute to set the value from what is returned from the web api.

    If you have not used web api previously, download the CRM Rest Builder by Jason Lattimer. This tool will help you build web api queries which you can then paste into your JavaScript code:

    github.com/.../CRMRESTBuilder

    Here is an example of an article on using web api (you can generate the code from Rest Builder) on this community:

    community.dynamics.com/.../ms-crm-2016-web-api-operations-retrieve-single-or-multiple-records

    Hope this helps.

  • Suggested answer
    Temmy Wahyu Raharjo Profile Picture
    Temmy Wahyu Raharjo 2,914 on at
    RE: Link of two lookups which are from different entities which don't have relationship between them

    Hi, this one can be done using presearch (Javascript). Something like this:

     function AddPreSearch(){
            var run;
            var fnCampaignFilter = function(){
                var b = Xrm.Page.getAttribute("new_b").getValue();
    			if(!b) return;
    			var bOfficerId = GetBOfficerId(b);
    			
                var filterXml = [
                    "<filter type='and'>",
                    "<condition attribute='new_advisorid' operator='eql' value="+bOfficerId+" />":""),
                    "</condition>",
                    "</filter>"].join("");
        
                Xrm.Page.getControl("new_c").addCustomFilter(filterXml);
            }
            return function(){
                if(!run){
                    Xrm.Page.getControl("new_c").addPreSearch(fnCampaignFilter);
                }
            }();
        };


    You must understand that you need retrieve entity B data to get the correct Officer. After you've got this Officer, you only need to give filter entity C lookup using this method. Btw, you called this method using OnLoad function. Everytime you want to changed entity C lookup value, it will populate based on the filter.

    Hope this help.

  • Suggested answer
    RaviKashyap Profile Picture
    RaviKashyap 55,410 on at
    RE: Link of two lookups which are from different entities which don't have relationship between them

    Hi,

    Without having a relationship between entity B & C how would you identify which Entity B record needs to be updated.

    So 2 answer your question, it is not possible to update the record without relating them (unless you have some other criteria to find the related record  for example say by name etc).

    Because you have this requirment, there must be some sort of link/ relation between entity B & C ( which you may have not yet created in CRM but exists as business requirement). I may be wrong, its just a thought.

    Hope this helps.

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans