Ivan Jovović
Ivan Jovović

Reputation: 5298

MS CRM 2011 - OnSave javascript - get entityId of related Entity

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?

Upvotes: 2

Views: 861

Answers (1)

BlueSam
BlueSam

Reputation: 1888

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();

Upvotes: 2

Related Questions