GlideModalForm Set a Field Value on the form

Matthew Knight
Tera Guru

I have created a UI action to display a GlideModalForm once clicked. This all works as expected but when I try to use either the addParm or setPreference options to preset a field to certain value it continues to remain blank.

I have included my script below:

MatthewKnight_0-1700822716987.png

 

The Modal is displayed but the description field remains empty

MatthewKnight_1-1700822767558.png

Appreciate any assistance here as the addParm or setPreference options are not working to achieve this.

1 ACCEPTED SOLUTION

Totally my bad, I misunderstood the requirements.

What you need has nothing to do with any UI Page or UI Macro.

What you need is to use parameter named sysparm_query; e.g:

var gmf = new GlideModalForm('Create Purchase Order', 'x_icaew_work_items_purchase_order');
gmf.setPreference('sysparm_query', 'description=Some description');
gmf.setPreference('sys_id', '-1');
gmf.render();

Basically that is the parameter that forms will look at to set initial values.

 

I'm assuming x_icaew_work_items_purchase_order is the name of the table containing Purchase Order records that you want to create.

View solution in original post

29 REPLIES 29

Hari Prasath
Tera Guru

Hi @Matthew Knight 

 

Have you tried addPreference('my_preference_key', 'my_preference_value'); . Please try this method and let me know. 

 

Please make the answer as helpful, if helped you accordingly.

 

Thanks,

Hari

 

Hi Hari,

Thank you for your message, unfortunately the addPreference option does not work. It actually prevents the form from rendering all together. 

Appreciate your input.

-O-
Kilo Patron
Kilo Patron

Adding a preference is only half of the whole solution.

The UI Page and/or UI Macro must also be built so that is "knows" of the preference (parameter) and uses it.

In other words the source of the UI Page and included/used UI Macros will also be needed for a solution.

 

Try as much as possible to use the sysparm_ prefix when naming parameters.

Hi @-O- ,

Thank you for your message.  Are you suggesting that I would need to build a form within a UI Page that renders in the Modal Form instead of the table record directly?

Many thanks