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
,id
and 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
.