setEnv & getEnv & askOnce may not be working in JavaScript

Post any Bulk Rename Utility support requirements here. Open to all registered users.

setEnv & getEnv & askOnce may not be working in JavaScript

Postby sbennet1 » Sun Nov 09, 2025 10:55 am

I may be missing something but I can get the askOnce function and the setEnv and getEnv var to work using the JavaScript test button see attached code
Code: Select all

// askOnce(prompt, defaultValue) shows a prompt dialog only once per batch with the given prompt text and optional default value.
// It returns the user's input as a string. Subsequent calls with the same prompt text return the stored answer without showing the dialog again.
// If the user cancels, an exception is thrown and execution stops.


// Here we just assign ENV to the result of askOnce with a prompt and default value.
ENV = askOnce("Enter new name for the file:", "xxx");           // default to current name if user leaves blank    //  SLB  ask once is not working    ?????????????????????????????????

alert ("ENV = " , ENV );    //  SLB    aksOnce is not working    ?????????????????????????????????????????????????????????

setEnv("BRU_ENV", "YYY");
YYY = getEnv("BRU_ENV");

alert  ("YYY =" , YYY );     //  SLB    setEnv & getEnv is not working    ?????????????????????????????????????????????????????

// To get the value of an environment variable, use getEnv("VAR_NAME").
// Example: if environment variable USERNAME = "Alice"
// If the original name is "file1", newName will be set to the value of USERNAME, e.g. "Alice"
newName = getEnv("PATH");
alert ("newName = " , newName );    //  SLB    get environment var not working    ????????????????????????????????????????????????


// To generate an exception in JavaScript, you can throw an error.
// This code will throw an error every time it runs, stopping the renaming process.
// Example: if name = "file", this script will throw an exception and not set newName.

throw new Error("This is a generated exception.");
sbennet1
 
Posts: 16
Joined: Mon Oct 27, 2025 1:55 pm

Re: setEnv & getEnv & askOnce may not be working in JavaScript

Postby Admin » Mon Nov 10, 2025 8:12 am

Hi, I am not sure that you can test these with the TEST button, but you can test them by selecting a few files.
Admin
Site Admin
 
Posts: 3118
Joined: Tue Mar 08, 2005 8:39 pm

Re: setEnv & getEnv & askOnce may not be working in JavaScript

Postby sbennet1 » Mon Nov 10, 2025 4:59 pm

I did try it on several files. It fails no matter which files i select. All of the alerts are returning empty strings.

I am running on a windows 11 machine with the latest software as an admin.
Does the code work on your machine?
What are you running?
What version of JavaScript is the program using?

Thanks for your help.
Steve
sbennet1
 
Posts: 16
Joined: Mon Oct 27, 2025 1:55 pm

Re: setEnv & getEnv & askOnce may not be working in JavaScript

Postby sbennet1 » Mon Nov 10, 2025 10:45 pm

It is working now. I had "," instead of "+" in the alert statement.

I have attached the code that i used that works. The compiler did not give an error on the number of arguments being wrong for the alert statement.

It does work with the test button.

Sorry for bothering you.

What version Java script are you using?

Code: Select all

setEnv("BRU_ENV", "xxx");
var YYY = getEnv("BRU_ENV");

alert ("YYY = " + YYY +            "    should be show as xxx");    // Should show xxx in alert                                            ??????????

var EnvPath = getEnv("PATH");

alert ("EnvPath = " + EnvPath  +   "    should be show as the PATH environment  ");       // Should show "the PATH" in alert               ??????????

// Here we just assign ENV to the result of askOnce with a prompt and default value.
var ENV = askOnce("Enter new name for the file:", "xxx"); //  SLB  ask once is not working   

alert ("ENV = " + ENV   +         "    should be show as the default xxx"  )  ;    // Should show "xxx" in alert if you take the default   ?????????
sbennet1
 
Posts: 16
Joined: Mon Oct 27, 2025 1:55 pm


Return to BRU Support