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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics 365 | Integration, Dataverse...
Suggested Answer

Trigger plugin when account has been viewed

(0) ShareShare
ReportReport
Posted on by 25

Hi there,

I am new to Dynamics 365 development. I created a plugin which executes when a new account has been created and works fine.

Now I would like to execute the same plugin when an Account is being viewed/Retrieved.

So this is what I have on my plugin code:

pastedimage1605854336283v2.png

And this is how I register a step on Retrieve of account.

pastedimage1605854211294v1.png

Could you please let me know what I am missing here?

Regards,

Gzee

I have the same question (0)
  • Suggested answer
    Bipin D365 Profile Picture
    28,983 Moderator on at

    Hi,

    Check below article to write your business logic on Retrieve plugin.

    nothingnessit.wordpress.com/.../

    Your steps are correct, check if you have registered as synchronous mode. Do you get the error message which you have in code when you open any record?

    Retrieve plugin will trigger when you open any record from Home page.

    Please mark my answer verified if i were helpful

  • Suggested answer
    Adrian Begovich Profile Picture
    1,027 Moderator on at

    Hi Gee1463,

    Have you considered on load JavaScript as an alternative? The best practice is to limit the registration of plug-ins for Retrieve and RetrieveMultiple messages. In general, it is not recommended to register plug-ins for these messages due to the risks associated with slowing down the requests to return an entity record or records from various entry points. You should only use Retrieve and RetrieveMultiple messages on rare occasions.

  • Gee1463 Profile Picture
    25 on at

    Hi Adrian, thanks a lot for your suggestion.

    Actually, I will need to make a call to an external API to gather some data an then add them in specific fields on the account form.

    I would like to make this call from the plugin instead of javascript. The reason is about exposing URLs and secret tokens of the API in the javascript. Do you have any other suggestion that I can make this work?

    Really appreciate your answer.

    Regards

  • Suggested answer
    Adrian Begovich Profile Picture
    1,027 Moderator on at

    Hi gee1463,

    The approach I would take is developing on load JavaScript that calls a custom action. This allows you to pass JavaScript variables as parameters of a C# function and receive a response. This will have better performance than the Retrieve and RetrieveMultiple messages approach, and URLs and secret tokens of the API will not be exposed. This article explains how to create JavaScript, custom actions, and plugins that work together. You will just need to modify the code to meet your specific scenario.

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using Microsoft.Xrm.Sdk;
     
    namespace Carl.AddNumbers
    {
        public class CustomAction : IPlugin
        {
            public void Execute(IServiceProvider serviceProvider)
            {
                IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
                IOrganizationServiceFactory factory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
                IOrganizationService service = factory.CreateOrganizationService(context.UserId);
     
                var Number1 = (int)context.InputParameters["Number1"];
                var Number2 = (int)context.InputParameters["Number2"];
                var Number3 = Number1   Number2;
     
                context.OutputParameters["Number3"] = Number3;
            }
        }
    }
    

    var parameters = {};
    parameters.Number1 = 7;
    parameters.Number2 = 9;
     
    var new_AddNumbersRequest = {
        Number1: parameters.Number1,
        Number2: parameters.Number2,
     
        getMetadata: function () {
            return {
                boundParameter: null,
                parameterTypes: {
                    "Number1": {
                        "typeName": "Edm.Int32",
                        "structuralProperty": 1
                    },
                    "Number2": {
                        "typeName": "Edm.Int32",
                        "structuralProperty": 1
                    }
                },
                operationType: 0,
                operationName: "new_AddNumbers"
            };
        }
    };
     
    Xrm.WebApi.online.execute(new_AddNumbersRequest).then(
        function success(result) {
            result.json().then(
                function (response) {
                    var sixteen = response.Number3;
                }
            );
        }
        ,
        function (error) {
            Xrm.Utility.alertDialog(error.message);
        }
    );

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Microsoft Dynamics 365 | Integration, Dataverse, and general topics

#1
Martin Dráb Profile Picture

Martin Dráb 49 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 38 Super User 2025 Season 2

#3
#ManoVerse Profile Picture

#ManoVerse 31

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans