It has often been seen that a RetrieveMultiple query that is very easy to write using the server side Query Expression objects using CRM webservices becomes difficult to achieve if we need to create a SOAP message for the same.
In this article we hope to explain each of the elements involved in the writing of SOAP messages to be used through Javascripts.
Let us take a simple RetrieveMultiple code as an example.
While writing the SOAP message the first component required is the SOAP envelope. This is the same at all times for all SOAP messages.
““+
“” xmlns:xsi=’http://www.w3.org/2001/XMLSchema-instance'”+
” xmlns:xsd=’http://www.w3.org/2001/XMLSchema’>”+
Next we need to add the Authentication Header that needs to be passed along with the SOAP message for successful authentication with the CRM Web service. CRM has an inbuilt function GenerateAuthenticationHeader() that can be used for this purpose.
var authenticationHeader = GenerateAuthenticationHeader();
SOAP Body is where the actual SDK message to be executed is included.
“”+
In our example we are using the RetrieveMultiple Message so we provide the Message name and the schema reference to the CRM webservices
“”+
The parameter to a Retrieve Multiple Message is always a query expression
QueryExpression query = new QueryExpression();
“” xsi:type=’q1:QueryExpression’>”+
Now include all properties of the Query object that you set.
Entity name
query.EntityName = EntityName.incident.ToString();
“incident”+
Column Set
query.ColumnSet = new AllColumns();
“”+
“”+
“title”+
“incidentid”+
“”+
“”+
Criteria
ConditionExpression condition = new ConditionExpression();
condition.AttributeName = “title”;
condition.Operator = ConditionOperator.Like;
condition.Values = new string [] {strSearchText};
“”+
“And”+
“”+
“”+
“title”+
“Like”+
“”+
“”+searchtext +””+
“”+
“”+
“”+
“”+
Here, we have used ‘Like’ condition operator, likewise one can use any of the sdk supported operators and change the values to be matched accordingly.
Order by
OrderExpression oe = new OrderExpression();
oe.AttributeName = “title”;
oe.OrderType = OrderType.Ascending;
query.Orders = new OrderExpression[]{oe};
“” +
“” +
“title” +
“Ascending” +
“” +
“” +
Once you have set all of these… your SOAP message is ready for execution.