Add variables dynamically on catalog form

lomouhamadou
Kilo Guru

Hi all,

Once again I am requesting help on our wonderful community.

I need to add variables on a form but dynamically.

So, I guess it is doable by using an "add button" option   that will generate the variables (I have to create 4 button every time we press the button) on the form every time we press the button.

Any idea, suggestion on how to handle this.

Thanks in advance for your time and help.

Regs,

Lô Mouhamadou

7 REPLIES 7

marcguy
ServiceNow Employee
ServiceNow Employee

one easy way, one slightly harder way.



easy way:


use a Catalog UI Policy to hide/show the variables on the form.


condition is another boolean varaible is true/false, thereby the user just needs to tick a variable to see all the other variables appear.



harder way:


Use Catalog client scripts, onload to hide the variables, onchange to display the variables again you can choose another true/false variable to tick/untick to hide/show the variables.



Even harder way but would give you a button


Create a button on a simple UI page and add a variable to reference that ui page, in the client script part of the ui page, display the variables when button is clicked.



To hide/show variables in a client script



g_form.setDisplay('variablename',false); (or true to show).



Marc


paramveer
Mega Guru

You can do the following ;



  • Create a variable set having the variables you want to generate(show) dynamically.
  • Create a on-load catalog client script, which will by default hide all these variable when catalog Item load.
  • use g_form.setDisplay('variable_name', false); apply this for all 4 variables
  • Create a button,using UI macro on catalog form.
  • On the button click event write code like : g_form.setDisplay('variable_name', true); this also for all 4 variables.



If you follow the above approach you can achieve the functionality.




Thanks,


Param


Deepa Srivastav
Kilo Sage

You could simple use UI Macro functionality. You can add a button on UI Macro to add rows in the same macro. Now, once all the necessary rows are added by the user and the item is submitted, you can store all the added values as a concatenated string in one variable.


You can check app in below link also. . copy the link and check, don't click it doesn't work..



ServiceNow Share



Mark Correct if it solved your issue or hit Like and Helpful if you find my response worthy.


Thanks,
Deepa


HI Deepa,

Link is not working, could you please share the the link.