microsoft / PowerPlatform-DataverseModelBuilder

Code Replica for the Microsoft Power Platform Dataverse Model Builder and supporting nuget packages
MIT License
13 stars 7 forks source link

`pac modelbuilder build` doesn't provide early-bound method to set output parameters for messages #24

Open filcole opened 3 months ago

filcole commented 3 months ago

It does not seem to be possible to set output parameters for a plugin associated with a custom API without using a magic string, e.g. 'Message'

context.OutputParameters["Message"] = "This is from the plugin";

The following command will output an earlybinding for the message pgc_BookingRule (for an Action or CustomAPI)

pac modelbuilder build --entitynamesfilter none --messagenamesfilter pgc_BookingRule --namespace pgc.DataverseModel --outDirectory DataverseModel

i.e.

    public partial class pgc_BookingRuleRequest : Microsoft.Xrm.Sdk.OrganizationRequest  { ... snip ... }

    public partial class pgc_BookingRuleResponse: Microsoft.Xrm.Sdk.OrganizationRequest  { ... snip ... }

It's not possible to set the properties in the pgc_BookingRuleResponse object because all the properties are read-only.

The model builder does not provide string values for the message properties (it does for entity properties, e.g. account.Fields.pgc_CustomField = "pgc_customfield"; )

Workarounds are:

  1. use the Early Bound Generator which allows output properties to be set. See http://dotnetdust.blogspot.com/2017/07/how-to-define-custom-action-parameters.html
  2. use magic strings when setting the output parameter, e.g.
context.OutputParameters["Success"] = "foo";
context.OutputParameters["Message"] = "bar";

Note: The EBG adds static Fields to the response class, e.g.

    public partial class AnS_BookingRuleResponse : Microsoft.Xrm.Sdk.OrganizationResponse
    {

        public static class Fields
        {
            public const string Success = "Success";
            public const string Message = "Message";
        }

Note: The EBG also allows for the properties to be writable:

        public string Message
        {
            get
            {
                if (this.Results.Contains("Message"))
                {
                    return ((string)(this.Results["Message"]));
                }
                else
                {
                    return default(string);
                }
            }
            set      //  <--- This is added by EBG
            {
                this.Results["Message"] = value;
            }
        }

It would be great if pac modelbuilder build was tweaked include both the static fields and the setting of properties.

MattB-msft commented 1 month ago

Accepted enhancement request, will include this in the next update to model builder.