2
votes

In MS CRM 2011 (on premise), I have 2 related entities, let's say A and B (1:N).

On a Form for A entity, I have associated view for entities B. Clicking on it will open a list of related entities B. Then I click "Add new B". When saving new entity B from this associated view, I want to perform a javascript check which needs ID of entity A to pass it to FetchXML query (javascript is attached onSave event, before B is saved).

How can I get entityId of associated entity A with javascript?

1

1 Answers

2
votes

For most out-of-the box entities, if you have the lookup field to the parent entity on the form, you can do something like (doesn't include proper error checking)

var idGuid = Xrm.Page.getAttribute("new_relatedrecordid").getValue()[0].id;

but for Order Products or one of the order line item record types in crm, you would get the ID by something like

var idGuid = Xrm.Page.getAttribute("salesorderid").getValue();