Softstuff Consulting
My occasional musings of a technical nature
  • Send us a message
  • About Softstuff Consulting
  • Privacy Policy
  • Main Website
Dynamics365 , JavaScript

Calling an action with parameters

by Ian Blair June 11, 2019 No Comments

In the previous post I showed how to call an action from javascript using the new features in the V9 javascript api, but in this post I will expand to show how to call the action with some simple parameters.

First we need to create an action with some input parameters.

Action screen with four parameters.

In this example the action has 4 input parameters, each one a different type. In the javascript object that is used to call the action the parameters get defined in parametertypes.

 function new_MyTestAction(bool_value,integer_value,string_value,decimal_value) {
        this.Bool_Input = sessions;
        this.Integer_Input = level;
        this.String_Input = subjects;
        this.Decimal_Input = residential;
        this.getMetadata = function () {
            return {
                boundParamter: null, operationType: 0, operationName: "new_MyTestAction",
                parameterTypes: {
                    "Bool_Input": {
                        "typeName": "Edm.Boolean",
                        "structuralProperty": 1 // Primitive Type
                    },
                    "Integer_Input": {
                        "typeName": "Edm.Int32",
                        "structuralProperty": 1 // Primitive Type
                    },
                    "String_Input": {
                        "typeName": "Edm.String",
                        "structuralProperty": 1 // Primitive Type
                    },
                    "Decimal_Input": {
                        "typeName": "Edm.Decimal",
                        "structuralProperty": 1 // Primitive Type
                    }
                },
            };
        }
    }

The parameters are defined according to the Primitive Data Types in the Entity Data Model. 

When executing the action call the parameters get passed in during the creation of the ‘new_MyTestAction’ object.

    var bool_value = true;
    var integer_value = 1;
    var string_value = "this is a string";
    var decimal_value = 3.142;

    ExecuteTestAction(new new_MyTestAction(bool_value, integer_value, string_value, decimal_value));

    function ExecuteTestAction(requestObject) {
        Xrm.WebApi.execute(requestObject).then(function (result) {
            var response = result["responseText"];
            var json = JSON.parse(response);
            dostuff();
        },
            function (error) {
                debugger;
                console.log(error.message);
            });
    }

 

 

  • Previous Calling an action from Javascript in a Web Resource6 years ago
  • Next Quickly generate an entities.cs file for early binding6 years ago

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Recent Posts

  • How to make your Powershell scripts more annoying
  • What motherboard is in my PC
  • A Dynamics365 plugin thought experiment
  • Registering a Dynamics365 plugin and I get an error
  • Going back in time with Dynamics365

Categories

  • Bootstrap
  • C#
  • CSS
  • Dot Net Core
  • Dynamics365
  • JavaScript
  • Powershell
  • T-SQL
  • Thoughts
  • VBScript
  • Visual Studio
  • Windows
  • Xamarin

Recent Comments

  • S0ftStuffB055 on Call a Dynamics365 workflow from JavaScript
  • Siva on Call a Dynamics365 workflow from JavaScript
  • TC Sharpe on Throw exceptions in Dynamics365 workflow plugins, or don’t
  • BigOwl on Throw exceptions in Dynamics365 workflow plugins, or don’t
  • CRMGod on Access a Dynamics365 embedded webresource

Archives

  • January 2021
  • May 2020
  • March 2020
  • February 2020
  • January 2020
  • December 2019
  • October 2019
  • June 2019
  • May 2019
  • February 2019
2025 Softstuff Consulting. Donna Theme powered by WordPress
  • Twitter