1

I Have Entity A and Entity B with N:1 Relationship through lookup field called lookupToB. In Entity A and Entity B I have option set field called grouping with using same global option set value. What I need to do is, I want to set value for field grouping in Entity A same with field grouping B if the relationship exist.

I know we can use Workflow for this, but I prefer to use javascript.

I can get name,idand entityType of the Entity B and populated in one custom field in Entity A by using this code.

    //get value in lookup(Entity B)
    var LookuptoB = Xrm.Page.data.entity.attributes.get("lookuptob").getValue()[0].name;
    var LookuptoBID = Xrm.Page.data.entity.attributes.get("lookuptob").getValue()[0].id;
    var LookuptoBType = Xrm.Page.data.entity.attributes.get("lookuptob").getValue()[0].entityType;

    //Set value into custom field A of Entity A
    Xrm.Page.getAttribute("custom_fielda").setValue(LookuptoB + LookuptoBID + LookuptoBType);
    Xrm.Page.getAttribute("custom_fielda").setSubmitMode("always");

But, I cannot get any others attributes of Entity B. For example:

//Get option set value in Entity B
var optionSetB = Xrm.Page.data.entity.attributes.get("lookuptob").getValue()[0].new_grouping;

//Set option set Value in Entity A
Xrm.Page.getAttribute("new_grouping").setValue(optionSetB);
Xrm.Page.getAttribute("new_grouping").setSubmitMode("always");

I m thinking this is not correct way to get and set value for option set field Boolean and OptionSet Attribute methods. But when I tried to get others attributes besides name,id and entityType of the Entity B and populated in one custom field in Entity A, the value display in that custom field in undefined.

xChaax
  • 193
  • 5
  • 27

1 Answers1

1

Few facts:

  1. Lookup field is a relationship, will have parent entity name, foreign key guid & display name of that parent record
  2. To pull extra attributes of that parent entity (ex.grouping picklist) you have to make a sdk call to retrieve & set in child entity
  3. If you have the lookup (n:1 relationship) you don’t need custom attribute to store concatenation values
  4. There are other ways to achieve this
  • Thanks Arun, If u dont mind can you share how to make a sdk call to retrieve & set in child entity. For option 4 weird thing is when I am using Mapping functionality I cannot find my grouping field in Source and Target Entity. – xChaax Nov 23 '17 at 04:04
  • @xChaax search online for samples - odata or webapi based on your CRM version – Arun Vinoth-Precog Tech - MVP Nov 23 '17 at 04:09
  • One more thing for the mapping functionality is it only apply for a new record of entity A ? Or for existing record when I change the value of lookuptob, will its reflect the value in grouping picklist in A based on grouping pick list in B ? – xChaax Nov 23 '17 at 04:12
  • @xChaax Mapping is only for new record – Arun Vinoth-Precog Tech - MVP Nov 23 '17 at 04:13
  • Dont think can use mapping because my entity is N:1 relationship. Everthing I created from Entity A then fill in lookup value of entity B. – xChaax Nov 23 '17 at 04:30
  • @xChaax mapping works only when creating child from inside parent record.. check other solutions like quick view.. don’t forget to upvote if it helps you.. – Arun Vinoth-Precog Tech - MVP Nov 23 '17 at 04:41