Sync Filter examples

From Resco's Wiki
Jump to: navigation, search
Sync Filter examples

This article lists several simpler examples of Sync Filter without linked entities. The examples are taken directly from the SyncFilter.xml configuration file and they are in FetchXML language. To learn more about the config file and how it corresponds to the Sync Filter configuration in Woodford, see Analyzing SyncFilter.xml.

Notes:

  • SyncFilter fetches are incomplete - they do not list attributes (entity properties). Attributes are added at run time. As a rule, all entity properties selected in Woodford are added.
  • Fetches shown below are for Dynamics. However, similar fetches can be used for Salesforce or Resco Cloud, too.
  • If you are looking for information about the various entities mentioned in the examples, try using Google, for example, search for "Dynamics entity_name entity type". You probably won't find custom entities such as pe_visitactivity in this way.
  • To get more information about state/status values, use Google to search for "Dynamics state status"
  • To learn about FetchXML operators, go to the FetchXML page on this wiki or search for "Dynamics 365 fetchxml operators" using Google.

Empty filter

In this example, all opportunities are downloaded. This is the same behavior as when the entity sync filter is missing.

<fetch version="1.0">
	<entity name="opportunity" />
</fetch>

All accounts except inactive

<fetch version="1.0">
	<entity name="account">
		<filter type="and">
			<condition attribute="statuscode" operator="ne" value="2"/>
		</filter>
	</entity>
</fetch>

Recent emails

This example synchronizes only emails modified during the previous 10 days.

<fetch version="1.0">
	<entity name="email">
		<filter type="and">
			<condition attribute="modifiedon" operator="last-x-days" value="10"/>
		</filter>
	</entity>
</fetch>

My bookable resources

Bookable resource is an entity used for Dynamics Field Service app. The filter returns records assigned to the current app user.

<fetch version="1.0">
	<entity name="bookableresource">
		<filter type="and">
			<condition attribute="userid" operator="eq-userid"/>
		</filter>
	</entity>
</fetch>

My leads+

The filter returns leads owned either by myself or by my team(s).

<fetch version="1.0">
	<entity name="lead">
		<filter type="and">
			<filter type="or">
				<condition attribute="ownerid" operator="eq-userid" />
				<condition attribute="ownerid" operator="eq-userteams" />
			</filter>
		</filter>
	</entity>
</fetch>

The same filter can be also expressed with a single condition:

<fetch version="1.0">
	<entity name="lead">
		<filter type="and">
			<condition attribute="ownerid" operator="eq-useroruserteams" />
		</filter>
	</entity>
</fetch>

Recent and upcoming appointments

The filter returns non-cancelled appointments from the last 3 months, as well as those scheduled for the next 24 months.

<fetch version="1.0">
	<entity name="appointment">
		<filter type="and">
			<condition attribute="statecode" operator="in">
				<value>1</value>
				<value>0</value>
				<value>3</value>
			</condition>
			<filter type="or">
				<condition attribute="scheduledend" operator="last-x-months" value="3"/>
				<condition attribute="scheduledend" operator="next-x-months" value="24"/>
			</filter>
		</filter>
	</entity>
</fetch>

Phone calls

Show only completed phone calls and my open phone calls scheduled for this or next year.

<fetch version="1.0">
	<entity name="phonecall">
		<filter type="and">
			<filter type="or">
				<condition attribute="scheduledstart" operator="this-year" />
				<condition attribute="scheduledstart" operator="next-year" />
			</filter>
			<filter type="or">
				<filter type="and">
					<condition attribute="ownerid" operator="eq-userid" />
					<condition attribute="statecode" operator="in">
						<value>1</value>
						<value>0</value>
					</condition>
				</filter>
				<filter type="and">
					<condition attribute="ownerid" operator="ne-userid" />
					<condition attribute="statecode" operator="eq" value="1" />
				</filter>
			</filter>
		</filter>
	</entity>
</fetch>

Active visit records from today or yesterday

<fetch version="1.0">
	<entity name="pe_visitactivity">
		<filter type="and">
			<filter type="or">
				<condition attribute="statuscode" operator="eq" value="1"/>
				<filter type="or">
					<condition attribute="modifiedon" operator="today"/>
					<condition attribute="modifiedon" operator="yesterday"/>
				</filter>
			</filter>
		</filter>
	</entity>
</fetch>

My tasks created within last 2 years

<fetch version="1.0">
	<entity name="task">
		<filter type="and">
			<condition attribute="createdon" operator="last-x-years" value="2" />
			<condition attribute="ownerid" operator="eq-userid" />
		</filter>
	</entity>
</fetch>

Private and team emails

My emails or emails owned by either myself or my team(s) which are up to 60 months old.

	<fetch version="1.0">
		<entity name="email">
			<filter type="and">
				<filter type="or">
					<condition attribute="createdon" operator="last-x-months" value="60" />
					<condition attribute="modifiedon" operator="last-x-months" value="60" />
				</filter>
				<filter type="or">
					<condition attribute="ownerid" operator="eq-useroruserteams" />
					<condition attribute="createdby" operator="eq-userid" />
				</filter>
			</filter>
		</entity>
	</fetch>

Related emails

Show only emails related (regardingobjectid) to my business unit.

<fetch version="1.0">
	<entity name="email">
		<filter type="and">
			<condition attribute="regardingobjectid" operator="eq-businessid" />
		</filter>
	</entity>
</fetch>

Open cases

Show all open cases from last 60 days.

<fetch version="1.0">
	<entity name="incident">
		<filter type="and">
			<condition attribute="modifiedon" operator="last-x-days" value="60" />
			<condition attribute="statuscode" operator="not-in">
				<value>5</value>
				<value>6</value>
			</condition>
		</filter>
	</entity>
</fetch>

Omit inactive templates

This filter shows all questionnaires except inactive templates.

<fetch version="1.0">
	<entity name="resco_questionnaire">
		<filter type="and">
			<filter type="or">
				<condition attribute="resco_istemplate" operator="ne" value="1" />
				<filter type="and">
					<condition attribute="resco_istemplate" operator="eq" value="1" />
					<condition attribute="statuscode" operator="eq" value="1" />
				</filter>
			</filter>
		</filter>
	</entity>
</fetch>

Complex example

This is an example of a more complex sync filter for the Annotation entity. Records must match one of the following conditions:

  • Annotations associated with opportunities or products
  • Notes (text annotations) not older than 3 months
  • Attachments (document annotations) associated with contacts, emails, tasks or appointments modified within last month
  • Attachments associated with accounts whose name ends with Products per Team.xls
  • Attachments associated with quotes max 12 months old
<fetch version="1.0">
	<entity name="annotation">
		<filter type="and">
			<filter type="or">
				<condition attribute="objecttypecode" operator="in">
					<value>3</value>
					<value>1024</value>
				</condition>
				<filter type="and">
					<condition attribute="isdocument" operator="eq" value="0"/>
					<condition attribute="modifiedon" operator="last-x-months" value="3"/>
				</filter>
				<filter type="and">
					<condition attribute="isdocument" operator="eq" value="1"/>
					<condition attribute="objecttypecode" operator="in">
						<value>2</value>
						<value>4202</value>
						<value>4212</value>
						<value>4201</value>
					</condition>
					<condition attribute="modifiedon" operator="last-x-months" value="1"/>
				</filter>
				<filter type="and">
					<condition attribute="isdocument" operator="eq" value="1"/>
					<condition attribute="objecttypecode" operator="eq" value="1"/>
					<condition attribute="subject" operator="like" value="%Products per Team.xls"/>
				</filter>
				<filter type="and">
					<condition attribute="isdocument" operator="eq" value="1"/>
					<condition attribute="objecttypecode" operator="eq" value="1084"/>
					<condition attribute="modifiedon" operator="last-x-months" value="12"/>
				</filter>
			</filter>
		</filter>
	</entity>
</fetch>