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.

Copy the value of a variable to a read only variable on the same catalog item

Cat
Mega Guru

Hi All,

 

I have a catalog item where there are 2 variables - article_name and article_name2.

article_name2 is a read only variable (single line text)

article_name is a single line text variable.

When the users fills in the article_name variable, I want the system to automatically populate article_name2 with the same information.

 

I have tried the following as a catalog client script, but it doesn't populate the field:

function onSubmit() { 
    var articleName = g_form.getValue('article_name');
    
    if (articleName) {
        // Set the value of the variable
        g_form.setValue('article_name2', articleName);
    }
    return true;
}

Is anyone able to help me achieve this?

 

Thank you

1 ACCEPTED SOLUTION

OlaN
Tera Sage
Tera Sage

Hi,

I would start by changing the logic to happen as an onChange Client script (have it interact on change of the first variable article_name).
Then the user can see the results before the form is submitted.

and in the script you would only need to do the setValue-part, and use the newValue input as basis, like this:

 

g_form.setValue('article_name2', newValue);

 

View solution in original post

5 REPLIES 5

Viraj Hudlikar
Tera Sage
Tera Sage

Hello @Cat 

 

VirajHudlikar_0-1764684413550.png

VirajHudlikar_1-1764684430441.png

function onChange(control, oldValue, newValue, isLoading) {
   if (isLoading) {
      return;
   }
   //Type appropriate comment here, and begin script below
   g_form.setValue('article_name_readonly',newValue);
}

 

Viraj_record (1).gif

 

If my response has helped you, hit the helpful button, and if your concern is solved, do mark my response as correct.

 

Thanks & Regards
Viraj Hudlikar.