Ad

CRM 2013 - Javascript Form Alert (onload Event) Referencing Child Records

I need some Jscript help for a CRM 2013 Form onload event that needs to reference a property from it's child records.

The parent entity is 'Contact'. The child entity is custom, lets call this entity 'Child'. The property referenced by the onload event is a Boolean two option field (yes/no), lets call this field 'Happy'.

What I need is for the 'Contact' form to display an alert message when none of the 'Child' records have the property 'Happy' set to 'yes'.

Example;

-If a 'Contact' has 2 'Child' records and both child records have property 'Happy' set to 'no', then show alert 'the children are not happy'

-If a 'Contact' has 2 'Child' records, one 'Child' record has 'Happy' set to 'yes', one 'Child' is set to 'no', then do not show alert

Any help with this would be great. Thanks

Ad

Answer

You'll need to perform a Rest Call (You can use the FetchXml Query Builder or some other tool to generate the URL you will need) to lookup the Child records from the onLoad. It should have a filter on it to filter the Child's parent Contact to be the Xrm.Page.data.entity.getId() (Might need to change the formatting on that) and for the Happy field to be true. If you don't get any results, throw your alert.

Ad
source: stackoverflow.com
Ad