Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Can't get action output parameter

Posted on by 65

1.  I create a action named "new_testAction" which is called by a workflow, and it has input parameter and output parameter.

WS000233.JPG

2. I register a plugin step on this action message .

WS000234.JPG

3. plugin code is here below.

    public class Try_WorkFlowPlugin_P : IPlugin
    {
        /// <summary>
        /// @function void Execute(IServiceProvider serviceProvider)
        /// @description 
        /// @param {IServiceProvider} serviceProvider
        /// @return {void} None
        /// </summary>
        public void Execute(IServiceProvider serviceProvider)
        {
            //Obtain the execution context from the service provider.
            var context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
            IOrganizationServiceFactory factory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
            if (factory == null)
            {
                throw new InvalidPluginExecutionException("Failed to retrieve the organization service.");
            }
            ITracingService tracingService = (ITracingService)serviceProvider.GetService(typeof(ITracingService));
            if (tracingService == null)
            {
                throw new InvalidPluginExecutionException("Failed to retrieve the tracing service.");
            }
            try
            {

                //Check if context message is not Update then return and does not execute code
                if (context.InputParameters.Contains("testAction"))
                {
#if DEBUG
                    tracingService.Trace("testAction parameter is in");
#endif
                }
                else
                {
#if DEBUG
                    tracingService.Trace("testAction parameter is not here");
#endif
                }

                if (context.InputParameters.Contains("outPut"))
                {
#if DEBUG
                    tracingService.Trace("outPut parameter is in");
#endif
                }
                else
                {
#if DEBUG
                    tracingService.Trace("outPut parameter is not here");
#endif
                }

                tracingService.Trace("output parameter is {0}", context.OutputParameters["outPut"]);

                context.OutputParameters["outPut"] = "SettingOutput";
                ((IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext))).OutputParameters["outPut"] = "SettingOutput";
                


            }
            catch (Exception e)
            {
#if DEBUG
                tracingService.Trace("Exception: {0} ", e.ToString());
#endif
                if (e.InnerException != null)
                {
                    throw new InvalidPluginExecutionException(e.InnerException.Message.ToString());
                }
                else
                {
                    throw;
                }
            }
        }
    }

4 the problem is , it create entity b which is general when parameter-output is null, i had filled output with "SettingOutput" ,why can't i get it in action.

Any ideas?

Thank you for your help.

best regards

*This post is locked for comments

  • Suggested answer
    RE: Can't get action output parameter

    If you have a  Stop step in the action   then delete it.  The  Stop step might kill the process and release the process space , which will set the output values to null.

  • Suggested answer
    Kokulan Profile Picture
    Kokulan 18,048 on at
    RE: Can't get action output parameter

    Hi

    I would suggest you first test to see if your action sets the output parameter as expected to rule out the issue is not with Action.

    You could create a dialog on any entity and call your action and display the output in a page and see the out value is returned.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Can't get action output parameter

    You can also get the outputs from the context.OutputParameters["<parametername>"]

  • Suggested answer
    a33ik Profile Picture
    a33ik 84,323 Most Valuable Professional on at
    RE: Can't get action output parameter

    Output parameters are available when accessed from other actions/workflows or code that called an action.

  • che Profile Picture
    che 65 on at
    RE: Can't get action output parameter

    Just a research, to find out whether action can get output parameter or not, and post the result to my leader~  : )

  • a33ik Profile Picture
    a33ik 84,323 Most Valuable Professional on at
    RE: Can't get action output parameter

    I'm curious - where do you use that output?

  • che Profile Picture
    che 65 on at
    RE: Can't get action output parameter

    Thank you for your replay,

    I had read your article before : ), It's short and very clear to show all i need .

    yeah , i confused too. why it doesn't work .  T_T

    Thank you all the same.

    Best regards,

    che

  • Suggested answer
    a33ik Profile Picture
    a33ik 84,323 Most Valuable Professional on at
    RE: Can't get action output parameter

    Hello,

    Your code looks correct. Anyway here a short article that I wrote when I investigated plugins on actions - butenko.pro/.../actions-usage-of-inputoutput-arguments-in-plugins-that-handle-actions

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!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans