WORK IN PROGRESS
Overview
Variables in Firecamp help you to reuse the values of requests, responses, or any other payload. You can set variables manually or via scripts in Firecamp. Here we'll see how to play with Variable in Scripts.
Use of variables in Scripts
Variables are scoped based on where they are defined, In Firecamp variables can be defined (aka scoped) in Globals, Environment, and Collection.
Globals
Globals scoped variables are defined in Globals. The script syntax would be like fc.globals.*
You can Get
, Set
, Unset
globals variables by using the following snippets.
Action | Snippet | Description |
---|---|---|
Get variable | fc.globals.get('variable_name') | Get value of globals variable |
Set variable | fc.globals.set('variable_name', 'value') | Set value of globals variable |
Unset variable | fc.globals.unset('variable_name') | Unset globals variable |
use of globals in scripts
// set 'itemId' in globals
fc.globals.set('itemId', 14);
//---
// get 'itemId' from globals
const itemId = fc.globals.get('itemId');
console.log(itemId); // log: 14
// ---
// unset 'itemId' in Globals
fc.globals.unset('itemId');
Environment
Environment scoped variables are defined in current Environment set in Firecamp. The script syntax of environment would be like fc.environment.*
You can Get
, Set
, Unset
environment variables by using the following snippets.
Action | Snippet | Description |
---|---|---|
Get variable | fc.environment.get('variable_name') | Get value of environment variable |
Set variable | fc.environment.set('variable_name', 'value') | Set value of environment variable |
Unset variable | fc.environment.unset('variable_name') | Unset environment variable |
use of environment variable in scripts
// set 'itemId' in current environment
fc.environment.set('itemId', 14);
//---
// get 'itemId' from current environment
const itemId = fc.environment.get('itemId');
console.log(itemId); // log: 14
// ---
// unset 'itemId' in current environment
fc.environment.unset('itemId');
Collection Variables
Collection scoped variables are defined in collection. The script syntax of collection variables would be like fc.collectionVariables.*
You can Get
, Set
, Unset
collection variables by using the following snippets.
Action | Snippet | Description |
---|---|---|
Get variable | fc.collectionVariables.get('variable_name') | Get value of collection variable |
Set variable | fc.collectionVariables.set('variable_name', 'value') | Set value of collection variable |
Unset variable | fc.collectionVariables.unset('variable_name') | Unset collection variable |
use of collection variable in scripts
// set 'itemId' in collection variables
fc.collectionVariables.set('itemId', 14);
//---
// get 'itemId' from collection variables
const itemId = fc.collectionVariables.get('itemId');
console.log(itemId); // log: 14
// ---
// unset 'itemId' in collection variables
fc.collectionVariables.unset('itemId');