Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

client script

Palmarp
Tera Contributor

Hi,

I am getting same error. I am working on ServiceNow Yokohama version. I added property and uncheck "Isolate script" field value. but still client script is not working. please suggest me solution.

4 REPLIES 4

Brian Lancaster
Kilo Patron

Based on your screenshot it look like you are trying to add the code after the closing back on the on change script.

BrianLancaster_0-1763668222384.png

 

Richard Montoux
Tera Contributor

Hi !
The code if(newValue === '1') is outside the onChange function, so it will not be interpreted.
If you want to write code outside the onChange function, you need another function and call it.

 

RichardMontoux_0-1763670195050.png

 

sumityadav8
Tera Contributor

Hii @Palmarp 

The issue is not with the “Isolate Script” option.
Your script is failing because the function is closed before the if condition, which means the if block is never executed.

 

Corrected Script 

function onChange(control, oldValue, newValue, isLoading) {  <--opening
    if (isLoading || newValue === '') {
        return;
    }

    // your logic must be INSIDE the function
    if (newValue === '1') {
        g_form.setValue('short_description', 'Test'); //E.g Setting Short description some Test Valur
    }
} <--   closing

 Glad the issue is resolved.
If the answer helped you, kindly mark the response as Helpful / Correct so the thread can be closed.
Thank you!

Technical Consultant

Sumit Y

sumityadav8
Tera Contributor

Hi @Palmarp 

The issue is not with the “Isolate Script” option.
Your script is failing because the function is closed before the if condition, which means the if block is never executed.

 

Corrected Script 

function onChange(control, oldValue, newValue, isLoading) {  <--opening
    if (isLoading || newValue === '') {
        return;
    }

    // your logic must be INSIDE the function
    if (newValue === '1') {
        g_form.setValue('short_description', 'Test'); //E.g Setting Short description some Test Valur
    }
} <--   closing

 Glad the issue is resolved.
If the answer helped you, kindly mark the response as Helpful / Correct so the thread can be closed.
Thank you!

Technical Consultant

Sumit Y