# Run same script in multiple environments

**URL:** <https://discuss.elastic.co/t/run-same-script-in-multiple-environments/316937>\
**Category:** Elastic Agent\
**Created:** [October 18, 2022, 10:31pm UTC](https://discuss.elastic.co/t/run-same-script-in-multiple-environments/316937 "2022-10-18T22:31:20Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kris\_MacKay](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kris_mackay/32/108978_2.png) [@Kris\_MacKay](https://discuss.elastic.co/u/Kris_MacKay)\
**Post date:** [October 18, 2022, 10:31pm UTC](https://discuss.elastic.co/t/run-same-script-in-multiple-environments/316937/1 "2022-10-18T22:31:20Z")

</div>

I'd like to reuse the same script for different environments. The opening URL is dependent on passed in parameter.  
For each Fleet agent policy, I'd like the passed in parameter to apply to just that script, but not shared with the others.

Would it be something like inserting under Advanced Browser Options --\> Synthetics agent options --\> Synthetics args the value "_params: {activeEnv: 0}_"

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/c/a/caf8a115343f951b0d38e8a18c8b1d5993615781.png)

Here's an example:

**Monitor Environment #1**

```auto
const MY_MONITOR_ENV_0 = 0;
const MY_MONITOR_ENV_1 = 1;

**let activeEnv = MY_MONITOR_ENV_0;**
const myLocation = [
  "https://www.computerhope.com/jargon/o/operator.htm",
  "https://www.computerhope.com/jargon/h/hardware.htm",
];

step ('Enter site',async () => {
		await page.goto(myLocation[**activeEnv**] );
});

```

======================

**Monitor Environment #2**

```auto
const MY_MONITOR_ENV_0 = 0;
const MY_MONITOR_ENV_1 = 1;

**let activeEnv = MY_MONITOR_ENV_1;**
const myLocation = [
  "https://www.computerhope.com/jargon/o/operator.htm",
  "https://www.computerhope.com/jargon/h/hardware.htm",
];

step ('Enter site',async () => {
		await page.goto(myLocation[**activeEnv**] );
});

```

---

<div class="post-metadata">

**Author:** ![Kris\_MacKay](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kris_mackay/32/108978_2.png) [@Kris\_MacKay](https://discuss.elastic.co/u/Kris_MacKay)\
**Post date:** [October 20, 2022, 12:34pm UTC](https://discuss.elastic.co/t/run-same-script-in-multiple-environments/316937/2 "2022-10-20T12:34:26Z")

</div>

I also tried adding parameters via the UI.  
On the command line, I tested and verified that I can pass in values  
npx @elastic/synthetics --inline **--params '{"loc": "DEV"}'**

and use the passed in value

```auto
switch(params.loc) {
	case "DEV":
		console.log('Set Dev environment');
		activeEnv = DEV_MONITOR_ENV;
		break;
	case "QA":
		console.log('Set QA environment');
		activeEnv = QA_MONITOR_ENV;
		break;	
	default:
		console.log('<' + params.loc + '> is unknown environment');
		activeEnv = 99;	// Throw error 
	
}

```

However when I insert the JSON value into Synthetic parameters entry field, the properties are not read in my code.  
For Source Type = Inline Script (_not Zip URL_)  
Under Advanced Browser Options --\> Synthetic agent options --\> Synthetics args  
I inserted JSON string **{"loc": "QA"}**

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/7/e/7e08b5d0b930d0347185c67d25a59db32a911093.png)

I received this error  
 ![image](https://us1.discourse-cdn.com/elastic/original/3X/0/3/03512b05911507cbe6cf1d732fe24f5b6e7f487d.png)

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [November 17, 2022, 12:35pm UTC](https://discuss.elastic.co/t/run-same-script-in-multiple-environments/316937/3 "2022-11-17T12:35:02Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
