May 17, 2024

Execute Multiple

In some cases we need to repeat the same operation. It may be creating a collection of records or updating a collection or records. We are good to do those via available CRUD operations of the Organization Service.

However if we do a collection within a loop, we should understand we repeat the same operation that result number of server calls which is not sufficient. Particularly, if you need to do this within a synchronous process it important to complete quickly rather keeping the user waiting.

In such situations, we would do execute multiple operations. Lets check the code snippet.

var executeMultipleRequest = new ExecuteMultipleRequest
{
    Settings = new ExecuteMultipleSettings { ContinueOnError = true, ReturnResponses = false },
    Requests = new OrganizationRequestCollection()
};

for (int i = 0; i < 5; i++)
{
    var paymentevaluation = new Entity("contact")
    {
        ["firstname"] = $"Test First Name {i}",
        ["lastname"] = $"Test Last Name {i}",
    };

    executeMultipleRequest.Requests.Add(new CreateRequest { Target = paymentevaluation });
}

var data = (ExecuteMultipleResponse)service.Execute(executeMultipleRequest);

foreach (var response in data.Responses)
{
    Console.WriteLine($"{response.RequestIndex}: {response.Fault}..");
}
Notice that we add all the entities to be created and execute once in this code. This is significantly faster than going through a loop.
Notes
> Keep in mind, maximum number of requests can be added to a execution is 1000.
> This also had a limitation of 2 concurrent operations, but now its removed.

May 11, 2024

ConditionOperator "Contains" doesnt work

When retrieving data using RetrieveMultiple we use different condition operators apart from Equal which is the most used one. 

Anyway, I noticed Contains operator is not working. For example below code, though looks alright, will not work. Its disappoint error message is not helpful either.

   
var query = new QueryExpression("account")
{
    ColumnSet = new ColumnSet("accountid", "name"),
    Criteria = new FilterExpression(LogicalOperator.And),
    TopCount = 10
};
query.Criteria.AddCondition("so_groupname", ConditionOperator.Contains, "expolanka");
Solution is to you like key work instead of Contains which does the same. Anyway, one thing to keep in mind is you need to use % mark for the task your check for. Check below;
   
query.Criteria.AddCondition("so_groupname", ConditionOperator.Like, "%expolanka%");