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 Resource2 years ago
  • Next Quickly generate an entities.cs file for early binding2 years ago

Leave a Reply Cancel reply

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

Recent Posts

  • A Dynamics365 plugin thought experiment
  • Registering a Dynamics365 plugin and I get an error
  • Going back in time with Dynamics365
  • Make using Windows for people with eyesight issues easier
  • Lets not forget VB script

Categories

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

Recent Comments

  • 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
  • Mike M on Access a Dynamics365 embedded webresource

Archives

  • May 2020
  • March 2020
  • February 2020
  • January 2020
  • December 2019
  • October 2019
  • June 2019
  • May 2019
  • February 2019
2021 Softstuff Consulting. Donna Theme powered by WordPress
  • Twitter
We use cookies to ensure that we give you the best experience on our website. If you continue to use this site we will assume that you are happy with it.I am happy