Add fields dynamically on form

ruzbehv
Mega Guru

Hi All,

 

I have a form for which users need to add additional fields.   Rather than offer them an "other" choice which limits them to just 1 entry, we want to have a "+" symbol which will allow them to create and name the field(s).   These fields should also be available for reporting.  

 

Another issue which needs to be considered is when two different people enter the same name as the dynamic field.

 

Any suggestions?


Regards,

 

RV

13 REPLIES 13

Hi Travis,



I need the new fields to populate in the same form section.   See below a screenshot of the area where I need the "+" button.   It would be in place of the text box for "Other".




Hi Ruzbehv,



A quick question, are these dynamic fields going to be unique to each record or should it add these fields to every record on the table?



For unique to each record:



You will need to create a formatter by following: Creating a Formatter - ServiceNow Wiki.



Your macro will include <script> </script> tags which contain the client side logic for:



1.   Loading the macro (getting already created fields and displaying them in the macro)


2.   Adding new fields


3.   Possibly removing existing fields (in case a mistake is made)


4.   Saving the dynamic field name / value pairs to a hidden text field on the form


Hi Travis,



Sorry for the delay.   It would be static fields (i.e. Other1, Other2, Other3, etc.)   I'm thinking of doing the following but need help with the script.



1. Create Other1 to Other25


2. When someone clicks the "+" button it would start showing "Other1".   Then the next time they click "+" it would show "Other2".



What do you think?



Regards,



RV


Hi Ruzbehv,



That could certainly work.   To accomplish this, here is one possible solution:



1.   Display all of your 'Other' fields on the form in their correct location


2.   Hide all the 'Other' fields using a UI Policy or Client Script


3.   Provide a UI Macro and Formatter to display the '+' on the form, add logic to this Macro which would show each 'Other' field progressively as it was clicked.


Hi Travis,



I'm fine with 1 and 2. Its the code for 3 that I need help with.



Regards,



RV