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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Getting Value from Parent Entity

(0) ShareShare
ReportReport
Posted on by

I have two entities:  Client (Parent) and Matter (Child to Client) ...... we're a law firm.

Anyway, When displaying a matter form, the field that is the lookup for the parent client displays only the client number.  That's fine, but I also want to display the client's name on the matter form as well (read only).

I've done some research.  Right now, it seems my answer is adding an OnChange event to the Client Number field and then using Javascript and the Xrm.Page.data.entity.getParent function to get the Client entity and then populate my Matter Form field with the Client entity's Client-Name attribute.

Is that the best option or is there a simpler/better way to accomplish this?

Thanks from a beginner,
Glen

 

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    ScottDurow Profile Picture
    21 on at

    Hi Glen,

    The getParent function will not give you the parent Client - it will only give you the parent entity to a particular attribute on the form. There is no Xrm.Page.data.entity.getParent function unfortunately.

    You will need to use the REST or SOAP end points to get the client name. I would suggest that you use a web resource to show the information rather than populate a field (unless you need to) - see blogs.msdn.com/.../showing-related-information-in-a-crm-2011-form.aspx

    hth

  • Glen W. Profile Picture
    on at

    Scott,

    Thank you for your response.  I'll have a look at the link you sent.  One quick question:  My thinking was that I use the ClientID field (Lookup) which displays on the matter form and find ITS parent to get the parent client entity.

    Will that work?

    Thanks,

    Glen

  • Suggested answer
    ScottDurow Profile Picture
    21 on at

    Absolutely - this is indeed the best way you can get the ClientID !

  • Glen W. Profile Picture
    on at

    But then what is the best way to display it on the form?  

    Sorry if these are simplistic questions, but I'm very new to CRM.

    Thanks,

    Glen

  • Verified answer
    ScottDurow Profile Picture
    21 on at

    Don't worry - I'm probably not explaining it well!

    The Client Lookup will get you the Client name field (which I think you are using for the client nuber) and Client Unique Identifier(GUID)

    To display another field (other than the standard field shown on the lookup) you will need to make a request to the server to get the other data. This can be done in the following ways:

    1. Use a Relationship mapping on the Client->Matter relationship to populate the client name field on the matter form. This will only work when you create a matter from the client record - and if the client name changes or the client on the matter changes, the name will not be updated. (www.powerobjects.com/.../microsoft-dynamics-crm-relationship-mappings-help-keep-customer-and-bill-to-customer-consistent)

    2. Within the JavaScript Onchange event of the Client field on the matter form, use the REST/SOAP end point to get the client name field and populate a text box on the matter form. This will work as long as the record is being updated via the form (not bulk update/import/workflow/sdk), and the client name never changes. To cater for this, you will also need a plugin/workflow to do the update server side.

    3. Create a webresrouce on the matter form that looks up the client ID from the parent Xrm context and then gets the name using the REST/SOAP endpoint and displays it as HTML.

    Option 3 is probably the easiest and least impact on your system, and is the subject of the link I provided - blogs.msdn.com/.../showing-related-information-in-a-crm-2011-form.aspx

    hth

  • Glen W. Profile Picture
    on at

    Thanks for the clear and detailed explanation.  You have been very helpful.

    Sincerely,

    Glen Wolinsky

  • Glen W. Profile Picture
    on at

    Scott,

    Sorry to bother again, but I can't seem to get it to work.  I followed the instructions provided in the link.  Below are the screenshots from my attempt.

     

    This is the Matter form.  The first textbox (Client Number) is field cpdc_clientnumberid as seen in the second screen shot below.

    3240.Field-Props.jpg

    5428.Web-Resource-Props.jpg

     

    This is how I defined the Web Resource.  Have I missed or messed up something?

     

    Any help would be greatly appreciated.

    Sincerely,
    Glen

  • Glen W. Profile Picture
    on at

    Found a comment on the blog page about having to designate the entity name in the parameter string if it is a custom entity.  Both ClientInfo and Matter are custom entities.

    My new parms string looks like this:

    lookup=cpdc_clientnumberid&entityName=cpdc_clientinfo&fields=cpdc_clientname&labels=Client Name

    Still doesn't work.    :o(

    - Glen

  • Suggested answer
    ScottDurow Profile Picture
    21 on at

    Hi Glen,

    I think the problem is that your fields should be the schema name and not the lowercase logical name.

    So check the cpdc_clientname attribute's SchemaName in the attributes list against the entity. It is probably something like cpdc_ClientName. The webresource uses the REST endpoint which requires schema names and not logical names.

    hth

  • Glen W. Profile Picture
    on at

    Scott,

    Thanks for your response.  I checked and double-checked and the names I used ARE the schema names.  Still not working.  Below is what I posted to the author on the blog.

    Thanks,

    Glen

    I have been trying for two days, but I can't seem to get this to work.  Any help would be greatly appreciated.

    Details

    ----------

    Two custom entities:

     1. Client Info (schema name:  cpdc_clientinfo)

     2. Matter (schema name: cpdc_matter)

    > Client Info record can have multiple Matters associated with it.

    > When displaying a matter, The Client Info picker displays the client NUMBER, but not the name.  Trying to use this solution to display that client name on the matter form without duplicating the data.

    Implementation

    ------------------------

    My WR Properties:   lookup=cpdc_clientnumberid&entityName=cpdc_clientinfo&fields=cpdc_clientname&labels=Client Name

    > cpdc_clientnumberid - name of the fild on the matter form that is the picker for the related Client Info entity

    > cpdc_clientinfo - name of the custom entity I'm trying to retrieve per previous blog comment above.

    > cpdc_clientname - name of the field from the custom entity I'm trying to retrieve and display.

    When I pull up the matter form, the WR field that should display the client name is just a div with blue background.  NO DATA.

    When I debug, It throws an error as indicated below.  Seemingly showing that retrieveReq.status IS NOT equal to 200.

       function retrieveReqCallBack(retrieveReq) {

           if (retrieveReq.readyState == 4 /* complete */) {

               if (retrieveReq.status == 200) {

                   //Success

                   entity = JSON.parse(retrieveReq.responseText).d;

                   LoadTable();

               }

               else {

    -->                throw new Error("Error retrieving Record");

               }

           }

       }

    I am in desperate need of getting this to work.  ANY HELP WOULD BE GREATLY APPRECIATED!!

    Thanks,

    Glen

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…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans