Tip #489: Limitations of Retrieve plugins

Calculated fields is one of the best new features and is indispensable for simple calculations. Keyword here is simple. Range of functions available in calculated fields is limited (though it continues to expand from release to release).

One of the “traditional” methods to add calculated field is to add a simple field and then create plugin on Retrieve and RetrieveMultiple messages. If field is part of the column list in either message, perform your voodoo and return the calculated value.

Smug developer that I am, that’s what I’ve done and reported to the customer. Who was rather disappointed with the result, as it turned out. Field was calculating fine but yielded very strange results when customer tried to build some charts using that field.

Humiliated, I’m happy to report that the following functionality won’t work for the fields calculated in Retrieve and RetrieveMultiple plugins:

  • Sorting on the column in the listviews
  • Using the column as aggregate value in charts

Come to think about it, that makes perfect sense. Sorting and aggregation is done as part of the T-SQL statement that runs on the SQL Server that has absolutely no clue about your plugin magic. As long as you and your customers are aware of these limitations, using plugins for calculations “on-the-fly” is perfectly fine.

3 thoughts on “Tip #489: Limitations of Retrieve plugins

  1. Clint Woods says:

    I have added some columns in a Filter Expression I added in my retrieve multiple plugin. Checking the FetchXML created and running it in XRMToolBox shows the Filter Expressions have been added all columns correctly displaying. Checking the ColumnSet.Columns.Count shows the correct number of Columns.

    HOWEVER, the output on the grid produced by Advanced Find does not show the columns I added in the plugin. It seems we need to update the “grid” XML or something. Have you figured out how to do this?

    clint

  2. AJIT says:

    I want consume Rest service to retrieve multiple data based on parent key into virtual entity .

    EvaluateEligibilityProgramServiceClient myClient = new EvaluateEligibilityProgramServiceClient(myBinding, endPointAddress);
    tracer.Trace(“CRMIntegrationServiceClient Created Successfully.”);

    eligibiltyStatusRequestDto request = new eligibiltyStatusRequestDto();

    string currentCustomerId = string.Empty;
    if (context.InputParameters.Contains(“Query”) && context.InputParameters[“Query”] is QueryExpression && context.MessageName == “RetrieveMultiple”)
    {
    QueryExpression qe = (QueryExpression)context.InputParameters[“Query”];
    ConditionExpression[] filters = qe.Criteria.Conditions.ToArray();
    foreach (var filter in filters)
    {
    currentCustomerId = filter.Values[0].ToString();
    }
    }
    string Id = “”;
    if (string.IsNullOrEmpty(currentCustomerId) == false)
    {
    ColumnSet colSet = new ColumnSet(new string[] { “inf_nin” });
    Entity contactRecord = service.Retrieve(“contact”, new Guid(currentCustomerId), colSet);

    if (contactRecord.Attributes.Contains(“inf_iqamaid”))
    Id = Convert.ToString(contactRecord.Attributes[“inf_plan”]);

    }

    request.userId = Convert.ToInt64(Id);
    request.locale = “en”;
    eligibiltyStatusResponseDto response = await myClient.getEligibiltyStatus(request);

Leave a Reply

Your email address will not be published. Required fields are marked *