Fetch all parents who does not have child

free resorces

In one of scenario I was looking for all available Assets only, means show only those assets who are available for particular data range. Just like get all parents who does not have any child.

So, after some googling i found below way, but i was showing all booked and non booked assets for given date range.

Out of the box it wont give NOT-IN result, for it we need to change ‘Inner’ to ‘Outer’

<link-entity name="bookableresourcebooking" from="resource" to="bookableresourceid" link-type="outer" alias="aj">

Here is the complete sample fetch XML…..

<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="true">

<entity name="bookableresource">

<attribute name="name" />

<attribute name="bookableresourceid" />

<order attribute="name" descending="false" />

<filter type="and">

<condition attribute="statecode" operator="eq" value="0" />

</filter>

<link-entity name="bookableresourcecategoryassn" from="resource" to="bookableresourceid" link-type="inner" alias="ai">

<filter type="and">

<condition attribute="resourcecategory" operator="eq" uiname="Backhoe" uitype="bookableresourcecategory" value="{798E6C02-3BBE-E711-8123-E0071B686A81}" />

</filter>

</link-entity>

<link-entity name="bookableresourcebooking" from="resource" to="bookableresourceid" link-type="outer" alias="aj">

<filter type="and">

<condition attribute="starttime" operator="on-or-after" value="2018-03-01" />

<condition attribute="endtime" operator="on-or-before" value="2018-03-31" />

<condition attribute="bookingstatus" operator="not-in">

<value uiname="Hard" uitype="bookingstatus">{6ABF1A73-DFB9-E711-8129-E0071B67C991}</value>

<value uiname="Soft" uitype="bookingstatus">{6BBF1A73-DFB9-E711-8129-E0071B67C991}</value>

</condition>

</filter>

</link-entity>

</entity>

</fetch>

 

But, it was not satisfactory one, as I was interested only for available assets. So with below little tweak its possible which include above tweak.

<condition entityname="bookableresourcebooking" attribute="resource" operator="null" />

and here is complete sample for it ….

<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="true">

<entity name="bookableresource">

<attribute name="name" />

<attribute name="bookableresourceid" />

<order attribute="name" descending="false" />

<filter type="and">

<condition attribute="statecode" operator="eq" value="0" />

<condition entityname="bookableresourcebooking" attribute="resource" operator="null" />

</filter>

<link-entity name="bookableresourcecategoryassn" from="resource" to="bookableresourceid" link-type="inner" alias="ai">

<filter type="and">

<condition attribute="resourcecategory" operator="eq" uiname="Backhoe" uitype="bookableresourcecategory" value="{798E6C02-3BBE-E711-8123-E0071B686A81}" />

</filter>

</link-entity>

<link-entity name="bookableresourcebooking" from="resource" to="bookableresourceid" link-type="outer" alias="aj">

<filter type="and">

<condition attribute="starttime" operator="on-or-after" value="2018-03-01" />

<condition attribute="endtime" operator="on-or-before" value="2018-03-31" />

<condition attribute="bookingstatus" operator="not-in">

<value uiname="Hard" uitype="bookingstatus">{6ABF1A73-DFB9-E711-8129-E0071B67C991}</value>

<value uiname="Soft" uitype="bookingstatus">{6BBF1A73-DFB9-E711-8129-E0071B67C991}</value>

</condition>

</filter>

</link-entity>

</entity>

</fetch>

Simple one but it will save hours.

Thanks!!