Sync Filter examples

From Resco's Wiki
Jump to navigation Jump to 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>

Exclude entity from download (stop filter)

Use a non-sensical condition (primary key = null) to exclude an entity from download. This filter cannot be fulfilled by any record and the sync downloader does not even send any query to the server.

<fetch>
	<entity name ="account">
		<filter>
			<condition attribute="accountid" operator="null"/> 
		</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>

Since Release 17.0, you can use the operator "Not Older Than X Days". It should work better/faster than combined condition next-x-months + last-x-months.

<condition attribute="scheduledend" operator="on-or-after" value="@@TODAY-90" />

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>

Active questionnaire templates and recent answers

This fetch for the questionnaire entity includes:

  • Active and published questionnaire templates
Consider including also archived templates if you are using full template dependency - to ensure that answered questionnaires dependent on archived templates can be displayed.
See Resco Inspections data model to find statuscode values for different template statuses.
  • Answered questionnaires completed within the last 30 days.

All snippets are excluded.

<fetch version="1.0">
  <entity name="resco_questionnaire">
    <filter type="and">
      <filter type="or">
        <filter type="and">
          <condition attribute="resco_istemplate" operator="eq" value="1"/>
          <filter type="or">
            <condition attribute="statuscode" operator="eq" value="1"/>
            <condition attribute="statuscode" operator="eq" value="473220002"/>
          </filter>
        </filter>
        <filter type="and">
          <condition attribute="resco_istemplate" operator="eq" value="0"/>
          <filter type="or">
            <condition attribute="modifiedon" operator="today"/>
            <condition attribute="modifiedon" operator="last-x-days" value="30"/>
          </filter>
        </filter>
      </filter>
      <filter type="or">
        <condition attribute="resco_issnippet" operator="eq" value="0"/>
        <condition attribute="resco_issnippet" operator="null"/>
      </filter>
    </filter>
  </entity>
</fetch>

A variant sync filter that includes staged questionnaires:

Sync filter example with staged questionnaires

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>