2
votes

We're writing a web-frontend for at Dynamics CRM 2011 system, using PHP and SOAP (NuSOAP). In the process of doing so we need to retrieve entities that has been updated since our last import.

I've looked around the existing CRM Frontend, to see if anything there might give a hint as what to add as criteria, but to no avail.

The xml for a standard query looks like this:

<RetrieveMultiple xmlns="http://schemas.microsoft.com/crm/2007/WebServices">
<query xmlns:q1="http://schemas.microsoft.com/crm/2006/Query" xsi:type="q1:QueryExpression">
    <q1:EntityName>new_arrangement</q1:EntityName>
    <q1:ColumnSet xsi:type="q1:ColumnSet">
        <q1:Attributes>
            <q1:Attribute>subject</q1:Attribute>
            <q1:Attribute>activitytypecode</q1:Attribute>
            <q1:Attribute>regardingobjectid</q1:Attribute>
            <q1:Attribute>scheduledstart</q1:Attribute>
            <q1:Attribute>scheduledend</q1:Attribute>
        </q1:Attributes>
    </q1:ColumnSet>
    <q1:Criteria>
        <q1:FilterOperator>And</q1:FilterOperator>
            <q1:Condition>
                <q1:AttributeName>statecode</q1:AttributeName>
                <q1:Operator>Equal</q1:Operator>
                <q1:Values>
                    <q1:Value xsi:type="xsd:string">Open</q1:Value>
                </q1:Values>
            </q1:Condition>
        </q1:Conditions>
    </q1:Criteria>
    <q1:Orders>
        <q1:Order>
            <q1:AttributeName>subject</q1:AttributeName>
            <q1:OrderType>Ascending</q1:OrderType>
        </q1:Order>
    </q1:Orders>
    <q1:Distinct>false</q1:Distinct>
    <q1:PageInfo>
        <q1:PageNumber>1</q1:PageNumber>
        <q1:Count>20</q1:Count>
    </q1:PageInfo>
</query>

So I'm looking for help with regards to which attribute I should add as a Condition.

1

1 Answers

1
votes

If your application can remember the date and time of the last import, then you should be able to get all the new records by checking the Modified On field, I believe every entity has it.

I think you will want a query like this (but in XML of course).

DateTime lastImportDate = ...;

QueryExpression q = new QueryExpression("contact");
q.Criteria.FilterOperator = LogicalOperator.And;
q.Criteria.AddCondition(new ConditionExpression("statecode", ConditionOperator.Equal, "Open"));
q.Criteria.AddCondition(new ConditionExpression("modifiedon", ConditionOperator.GreaterThan, lastImportDate);