Tech Support > Microsoft Windows > Windows CRM > How to Retrieve Random Records through webservice method
How to Retrieve Random Records through webservice method
Posted by Sol on February 25th, 2008


Hi All,

I'm writing an application that retrieve records from CRM 3.0 automatically
using the web service. My question is, is there any way we can retrieve
records randomly by using any webservice method? Like we can use RAND() or
NEWID() to achieve this in SQL. Please help me if you have any idea about it.

My sample method code is given below:

CrmService service = new CrmService();

RetrieveMultipleRequest request2 = new RetrieveMultipleRequest();


// Create the ConditionExpression object.
ConditionExpression condition = new ConditionExpression();

// Set the condition to be the city equals Sammamish.
condition.AttributeName = "new_accounttype";
condition.Operator = ConditionOperator.Equal;
condition.Values = new string[] {type };

OrderExpression orderexp = new OrderExpression();
orderexp.AttributeName = "name";
orderexp.OrderType = OrderType.Ascending;

// Create the FilterExpression object.
FilterExpression filter = new FilterExpression();

// Set the filter's properties.
filter.FilterOperator = LogicalOperator.Or;
filter.Conditions = new ConditionExpression[] { condition };


// Create the QueryExpression object.
QueryExpression query = new QueryExpression();

// Set the QueryExpression object's properties.
query.EntityName = "account";
query.ColumnSet = new AllColumns();
query.Criteria = filter;
query.Orders = new OrderExpression[] { orderexp };



// Set the Request object's properties.
request2.Query = query;

// Execute the request.
RetrieveMultipleResponse response2 =
(RetrieveMultipleResponse)service.Execute(request2 );

BusinessEntityCollection entities =
response2.BusinessEntityCollection;



What i want, is to get accounts records in random order, what code should i
add to the above method in order to achieve that.

Thanks in advance.

Kind Regards,
--

Sol

Posted by George Doubinski on February 25th, 2008


Hi Sol,

as far as I know, there is no way to randomise the order of records
returned, however

if that's what you want then why don't you get the records as they come from
the database, then simply randomise the order on the client's side?

Hope this helps
--
George Doubinski
CRM Certified Professional - Developer
Blog: http://crm.georged.id.au/


"Sol" <Sol@discussions.microsoft.com> wrote in message
news:5A7A8A39-D7E1-45B7-AC31-3B2DDF75FB05@microsoft.com...


Posted by Sol on February 27th, 2008


Hi George,

Many Thanks for your reply. Yeah, i can rendomise them on client side, i
just wanted to reduce the processing time.


Again thanks for your time.


--

Sol


"George Doubinski" wrote:


Similar Posts