{Power Script}Add Dynamic options in an option set in Model driven Apps


In this article, we are going to see how to create a custom option set field and add dynamic options to the custom option set using JavaScript.

Step 1: Create an Option set field and add one option.


Step 2: Declare an array and Store three values.

Step 3: Write the script below.

function setOptions(executionContext)


var formContext = executionContext.getFormContext();

var optionCode = formContext.getControl(arg);


countryArray = [“India”,”Singapore”,”Malaysia”];

var index = 1;

for (var i=0; i< countryArray.length; i++)


var Name = countryArray[i];

var obj = {};

obj[“text”] = Name;

obj[“value”] = index;


index = index + 1;



Step 4: Deploy the Web resource and add the function on the OnLoad event of the form.



Hope it helps and Power 365ing as usual!

Any problem in Power Platform or Dynamics 365 – end user, Microsoft partner or an individual?

Problem Area – Technical, Functional, Training, Development or consulting?

I am here to help, get in touch here: Click here



Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s