Creating a number flag

This section describes how to define a number flag.

Understanding number flags

Number flags are flags that can have multiple number values. When you create a number flag in your application, you define the default value and all the other values this flag can have. Like simple boolean flags, the number flag name is derived from the flag variable name.

Creating a container class and defining a feature flag

To add a number flag, you need two things:

  • A container class for your flags

  • A defined flag inside the container class

In the example below, a number flag is defined with the name titleSize. The flag name is derived from the flag variable name. The titleSize flag has a default value of 12.

If you need a number flag to be more dynamic with regards to value, you can define a number flag in the code with only one value (which is also the default value). This will result in a Free Text input field when configuring the flag’s through the CloudBees Feature Management dashboard.

In the example below, the title size can be any one of 12, 14, 18 and 24. By default, it will be 12.

React Native JavaScript Node.js JavaScript SSR .NET
const flags = {
  titleSize: new Rox.RoxNumber(12, [12, 14, 18, 24]),
};
const flags = {
  titleSize: new Rox.RoxNumber(12, [12, 14, 18, 24]),
};
const flags = {
  titleSize: new Rox.RoxNumber(12, [12, 14, 18, 24]),
};
import {RoxNumber} from 'rox-ssr';
const flags = {
  titleSize: new Rox.RoxNumber(12, [12, 14, 18, 24]),
};
public RoxInt titleSize = new RoxInt(5, new List<int>() { 8, 13 });
public RoxDouble speiclaNumber = new RoxDouble(3.14, new List<int>() { 2.71, 0.577 });

Registering the container class

Once you have the container class, you need to register its instance to the CloudBees Feature Management SDK. This is done with the Rox.register SDK function.

The namespace parameter is a logical separation between containers and can be used to find flags on the dashboard.

Important notes

  • You can not call Rox.setup() twice in the same runtime.

  • A namespace can only be registered once.

React Native JavaScript Node.js JavaScript SSR .NET
const flags = {
  // define Rox entities here
}
Rox.register('<namespace>', flags);
await Rox.setup('<ROLLOUT_KEY>');
const flags = {
  // define Rox entities here
}
Rox.register('<namespace>', flags);
Rox.setup('<ROLLOUT_KEY>');
const flags = {
  // define Rox entities here
}
Rox.register('<namespace>', flags);
await Rox.setup('<ROLLOUT_KEY>');
import {Rox} from 'rox-ssr';
const flags = {
  // define Rox entities here
}
Rox.register('<namespace>', flags);
Rox.setup('<ROLLOUT_KEY>');
Container flags = new Container();
Rox.Register("<namespace>", flags);
await Rox.Setup(<ROLLOUT_KEY>);

Using a number flag

React Native JavaScript Node.js JavaScript SSR .NET
  console.log('Title size is ' + flags.titleColors.getValue());
  console.log('Title size is ' + flags.titleColors.getValue());
  console.log('Title size is ' + flags.titleColors.getValue());
  console.log('Title size is ' + flags.titleColors.getValue());
  Console.WriteLine("Title size is {0}", flags.titleSize.GetValue());
  Console.WriteLine("The speicla number is {0}, flags.speiclaNumber.GetValue());

Flag freeze level Flag freeze is available on client side SDKs by default.

  • SDK version 4.x the default is set to untilForeground

  • SDK version 5.0 or later the default is set to none

See Understanding a flag freeze for more information.