web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Get return from plugin within JavaScript / Custom Action

(0) ShareShare
ReportReport
Posted on by 510

Hi guys.

I need suggestions about the 2 solutions below:

Description: I need to create/update some records against the selected records in the opportunity view. So, the user will selected some records in the view, and then will press a home grid ribbon button to execute the logic against the selected records and refresh the page after that. So, what is the best way for doing that?

Solution 1: Use JavaScript Web API to execute all the create/update logic and after that, refresh the grid or show an error.

Solution 2: Use JavaScript to call a custom action, then the custom action calls the plugin. Get the return (error or success) from the plugin in my action and if success, refresh the grid view, else show error.

Thanks

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Mahendar Pal Profile Picture
    45,095 on at

    Hi,

    You won't be able to communicate easily between plugin and grid, so better to go with solution 1, you can refresh location with script.

    Thanks

  • HenriquePalomo Profile Picture
    510 on at

    I've the two solutions implemented doing the same thing, just for tests.

    The first solution, with Web API, all the code is in just one file, so looks more organised in my opinion.

    In the other hand, the second solution was done by JavaScript, Action and Plugin.

    Conclusion, the first solution for me looks better, but i don't know about the performance point of view if the first solution is better than the second one.

    What do you think?

  • Suggested answer
    Ivan Ficko Profile Picture
    1,380 on at

    I really don't see any benefit of the 2nd solution. The first solution will help you to manage it better in future because everything related to this use case is in one place and if you have tons of workflows that trigger each other in CRM it can be really painful when it comes to debugging.

    My opinion is that you don't make simple things too complex if you are not 100% sure that it must be done in a complex way because you will regret it later.

    I did the same mistake on one of my first CRM projects (still ongoing) and I still have headaches when I need to fix some bugs in a solution that is made like that.

  • Suggested answer
    Aric Levin - MVP Profile Picture
    30,190 Moderator on at

    Hi Henrique,

    Have done both implementation, and they both work well.

    Basically you need to loop through the selected records, and then either call webapi function on each record, or call an action on each record.

    There are advantages and disadvantages to each, but I guess the question here would be what work do you need to perform on each record. If these are simple updates and no manipulation that would require you to use .net code, there is no real reason to use Custom Actions.

    Hope this helps.

  • HenriquePalomo Profile Picture
    510 on at

    Hi guys.

    Thanks a million for your answer.

    @Ivan Ficko I agree with you about having everything in a web resource, in my opinion it's so much easier, clean and organised to do this with Web API. But also, like @Aric Levin said, the second solution would be better just in case of the Web API do not fit the requirement, like something that could be done just using C# .Net

    @Aric Levin Have you ever tried to use Batch operation with Web Api instead of loop through the records? I tried, but without success. But i did not spent much time on that, so i need to take a look on it again another day with calm.

    What do you mean with 'no manipulations'? The customer business requirement basically will be to create 20 entity records against 10 opportunities. Do you see any performance problem on that using create loop through the records?

    Batch Operations

    community.dynamics.com/.../web-api-bulk-operations

    Regards

    Henrique

  • Aric Levin - MVP Profile Picture
    30,190 Moderator on at

    Sorry Henrique,

    Have not used webapi batch operations.

    I guess one thing I misread is you are using the opportunities view not a subgrid. Should not be any different with the exception of the number of records.

    Saying that I would think the webapi route would be a better route. Have you tried using batch operations. Did you get any errors doing that, or are just looking for options?

    What I meant with manipulations is what you wrote in the beginning is something that would require .Net code, and cannot be done in JScript.

    Creation of 20 entity records should not be too time consuming especially using WebAPI or Actions. Of course using a For Loop would have performance degradation, but we are not talking about a lot of records.

    I am not sure your timeline, but you might be able to use some of the existing webapi libraries (Dynamics Web Api library by AlexandrRogov or Xrm.Tools.CRMWebApi library by David Yack), but at this point I don't think they have batch commands. Possibly sometime soon. It seems like they are under development.

    Hope this helps.

  • Suggested answer
    RaviKashyap Profile Picture
    55,410 Moderator on at

    Hi Henrique,

    How about workflow?  

    Creating a custom workflow activity and call it from a real time workflow which run on demand. So you go the opportunity view, select the record for which you need to run the logic, click run workflow and select the workflow to run.

  • Aric Levin - MVP Profile Picture
    30,190 Moderator on at

    If Ravi's solution works, you can create a button using Ribbon Workbench that will execute the workflow as well, so that you select all records, and execute the workflow on those records using your own custom button.

  • Suggested answer
    HenriquePalomo Profile Picture
    510 on at

    @Aric Levin I'm just looking for the best option for doing my business requirement.

    @Ravi Custom workflow activity would be almost the same hard work as the plugin, i prefer using Custom workflow activity in much cases because of it's more flexible than a plugin, but in this specific case, I'm thinking that Web API fit better, because the code needs to run after the user interaction (selecting some records and button click).

  • Verified answer
    HenriquePalomo Profile Picture
    510 on at

    Conclusion here in my opinion based on what we've talked about and after some tests:

    1. Call Web API from Ribbon button if the logic behind code it will not consume much performance or if it would be possible to do everything within javascript.

    2. Plugin/Custom workflow Activity called from Ribbon Button+Custom Action if we have a potentially problem with performance or if we have any restrictions that could be resolved just using C#, .NET

    Thanks for your opinions guys.

    Regards.

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
JS-09031509-0 Profile Picture

JS-09031509-0 3

#2
AS-17030037-0 Profile Picture

AS-17030037-0 2

#2
Mark Eckert Profile Picture

Mark Eckert 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans