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

So 1st of all the call to GlideModalForm is not correct, the parameters it accepts are:

GlideModalForm.prototype.initialize(id, readOnly, width, height)

So in the Script field you should have something like:

var dialog = new GlideModalForm('x_icaew_work_items_purchase_order');

 

If you want to set a title you have to than write:

var title = 'Create Purchase Order';
dialog.setTitle(title);

of course before rendering it.

 

Other than that you should follow what @Tai Vu quoted from "The SN Nerd".

To answer your question about UI Macros, those are building blocks that can be used in UI Pages, or nested one inside another, to enable re-usability.

But for the purpose of solving your current problem, just read UI Page where UI Macro is shown in the picture.

Hello @-O- ,

Thank you for your response. I think there must be a knowledge gap here for me as I have created a UI Page exactly as detailed in the further post but have no idea how this translates to rendering onto my GlideModalForm. 

MatthewKnight_0-1700832403136.png

 

MatthewKnight_1-1700832425220.png

I understand the need to create a preference in order to set one but cannot see how this would then be used to set a field value on the rendered form. 

 

Appreciate your help but think I will need to explore an alternative 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.

-O-
Kilo Patron
Kilo Patron

To add to that, sysparm_query is key-value pairs joined by the ^ character, where the key is the name of a field and value is the value to set for that field; e.g:

 

caller=a60da68c97b2f114594ffbc71153afde^short_description=Can't open Excel^description=When I double-click the Excel icon on my desktop nothing happens.

 

The above

  • will set field caller to the user having that sys_id,
  • will set field short_description to "Can't open Excel" and
  • will set field description to "When I double-click the Excel icon on my desktop nothing happens."

Looks kinda' like a simple encoded query.

 

This is perfect thank you so much @-O- 

 

I can now generate a new Purchase Order from within a record and prefill the required field as need.

 

Appreciate your help with this