Provisior Tech Blog

Self-service by default

Single post

How to: Fill a Form field with the result of a REST api

In September 2018 we released a version of Provisior in which we introduced a nice new feature: The ability to bind the output of a Powershell script as the source for a (multi-value) field in our dynamic Forms (link in Dutch only). This opened a whole new world for our dynamic Forms, which btw were already very powerful and flexible ofcourse 😉

When you are working with Forms for collecting information from your employees, sooner or later you will need a dropdown list, a bunch of radio buttons or perhaps a multi select field. To maintain the contents of these types of field, ideally you do not want to have to do that manually. Especially if the content is dynamic or the option list is large. You can imagine if you can bind the output of a Powershell script to these type of fields the options are endless…

In this article I will begin with a pretty simple example. We will bind the result of a REST api to a dropdown list.

Go to the Admin section of the Provisior portal and create a new Powershell script in the Powershell section. Make sure you mark the ReturnType “FormData”. Paste in this Powershell script which makes a call to a public api, returning all current countries in the world as an array of values:

$uri = ""
$response = Invoke-RestMethod -Uri $uri
$result = $response | ForEach-Object { $ }
return $result

Next create a new Form in the Products section and add a dropdown list. Make sure “Also use API for items” is checked and fill in “/WebApi/Powershell/nameofscript” for “Options Data URL”. Using the preview option of Forms, you can easily check the result. Pretty easy, right?

Write a Comment

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