Azure Functions in Nintex Workflow Cloud: Random Number Generator

  • 28 September 2020
  • 1 reply

Badge +9

Extending Nintex Workflow Cloud Further with Azure Functions

Nintex Workflow cloud allows workflow developers to build robust workflows using a number of different actions in the Nintex Workflow Cloud designer. However, sometimes an action that needs to be completed is not available out-of-the-box. A workflow developer could look for a web service that could accomplish the action requirement, but what if you wanted more control of the action and not be beholden to the availability of the web service? Azure functions to the rescue!


In this example, I need to be able to generate a random number to select a winner of a survey contest in which users entered the contest by submitting anonymous forms in Nintex Workflow Cloud. Once the survey ends, I want to select a submission at random and then notify the winner. Let's head over to our Azure portal and create a new Azure Function!


Azure Functions Example: Oversimplified

One of the great features of Azure Functions is that you can choose the coding language of your choice to build a function, but in this example I will be using Node.js. There are two parameters I want to collect:

  • Minimum Value
  • Maximum Value


Based on the values entered, the function will provide you a random number value that is within the range of the minimum and maximum values supplied. Below is the code to achieve this requirement:


module.exports = function (context, req) { context.log('JavaScript HTTP trigger function processed a request.'); var min = req.body.min; var max = req.body.max; minInt = parseFloat(min); maxInt = parseFloat(max); function getRandomNum (n,x) { return parseFloat(Math.floor(Math.random() * (x- n)) + n); } res = getRandomNum(minInt, maxInt); context.done(null, res); };

Next, we will take advantage of another great feature of Nintex Workflow Cloud.

Custom Connectors: The Magic on Top of the Magic

Nintex Workflow Cloud allows you to add custom connectors from third-party RESTful web services utilizing the OpenAPI standard. You will be able to build the API definition of the service, if one does not already exist, and import that API definition into your Nintex Workflow Cloud tenant to be used as if it is a native action in Nintex Workflow Cloud.


Luckily for us, we built this service ourselves, so it shouldn't be hard to write the API definition. The definition was built to have a dynamic subdomain for the host URL, so you may point it to your Azure tenant functions resource. Also to note, although this API definition is calling for Basic Authentication, it is only added as a way to dynamically enter your subdomain. So feel free to use ' ' blank spaces for username and password. Although, if you did need to include some sort of authentication to make a call to the function, that is possible too.


To make easy, here is what the definition would look like:

{ "swagger": "2.0", "info": { "description": "Generate Random Numbers", "version": "1.0.0", "title": "Random Number Generator" }, "host": "", "x-ntx-host": "{{subdomain}}", "basePath": "/api", "schemes": [ "https" ], "security": [ { "basic": [] } ], "securityDefinitions": { "basic": { "type": "basic", "x-ntx-connection-properties": { "type": "object", "properties": { "subdomain": { "type": "string", "title": "Subdomain", "description": "Your Azure tenant name" } }, "required": [ "subdomain" ] } } }, "paths": { "/httpTriggerJS1": { "post": { "x-ntx-summary": "Random Number Generator", "description": "", "operationId": "randomNum", "consumes": [ "application/json" ], "produces": [ "application/json" ], "parameters": [ { "in": "body", "name": "body", "description": "", "required": true, "schema": { "$ref": "#/definitions/req" } } ], "responses": { "200": { "description": "Hooray!", "schema": { "type": "string" } }, "405": { "description": "Invalid input" } } } } }, "definitions": { "req": { "type": "object", "properties": { "min": { "type": "integer" }, "max": { "type": "integer" } } } } }

Quickly get the Random Number Generator action in your Nintex Workflow Cloud tenant!


Speaking of the Nintex Process Accelerator Gallery, if you would like to see what other custom connectors, process map templates, workflow templates, and Nintex RPA templates are available to get you ahead of the process game, I highly recommend heading over to the Nintex Process Accelerator Gallery and browsing the available templates and tools!


Once you have downloaded the custom connector from the gallery, you will then head over to your Nintex Workflow Cloud tenant and click on Xtensions on the left-hand pane to import your custom connector. Follow the prompts (don't forget the ' ' for username and password in this example!) and now you will have the ability to encode or decode string values in your Nintex Workflow tenant.


Best answer by butlerj 29 September 2020, 17:08

View original

1 reply

Userlevel 5
Badge +19

Awesome post @sean_fiene! Will definitely check out some of the other connections on the Gallery.