Skip to main content

Notifications

Customer experience | Sales, Customer Insights,...
Unanswered

Asynchronously triggering a Custom API action from a plugin

Posted on by 5

Hi all,

I'm attempting to update a plugin that's currently timeing out when running a Custom Api action repeatedly for different entities. Right now the only way I can do this is using an external program to trigger the actions asynchronously, but I'd like to get this running from within a plugin.

I've already tried using the ExecuteAsyncRequest class, but this doesn't seem to work with custom API requests, and the ExecuteMultipleRequest class, which forces you to wait until all requests are finished.

I don't need to read the responses once the jobs are started as the results are logged elsewhere, and the order the requests are executed in don't matter.

  • ATBennett Profile Picture
    ATBennett 5 on at
    RE: Asynchronously triggering a Custom API action from a plugin

    Using a foreach loop is how the plugin was originally written, but there's simply too much work to do synchronously in 2 minutes. For the time being I've switched it to use the ExecuteMultipleRequest class as (based on my testing) this continues to execute even if the original plugin timed out minutes ago. I think the best long term solution to this is going to be moving the logic out into an azure function that's triggered by the plugin.

  • RodRodriguez Profile Picture
    RodRodriguez on at
    RE: Asynchronously triggering a Custom API action from a plugin

    Howdy!

    Instead of batching them and using execute multiple, have you looked at simply executing them individually?

    Per the documentation:

    docs.microsoft.com/.../execute-multiple-requests

    "Custom code in the form of plug-ins and custom workflow activities may execute ExecuteMultipleRequest. However, this is not recommended"

    Following the guidance here:

    docs.microsoft.com/.../avoid-batch-requests-plugin

    In the "Additional Information" sections it states:

    ExecuteMultiple and ExecuteTransaction messages are considered batch request messages. Their purpose is to minimize round trips between client and server over high-latency connections. Plug-ins either execute directly within the application process or in close proximity when sandbox-isolated, meaning latency is rarely an issue. Plug-in code should be very focused operations that execute quickly and minimize blocking to avoid exceeding timeout thresholds and ensure a responsive system for synchronous scenarios. Simply submit each request directly instead of batching them and submitting as a single request.

    For example: foreach (request in requests) service.Execute(request)

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,240 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,149 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans