- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-24-2023 02:47 AM
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:
The Modal is displayed but the description field remains empty
Appreciate any assistance here as the addParm or setPreference options are not working to achieve this.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-24-2023 06:03 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-24-2023 04:29 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-24-2023 05:28 AM
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.
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-24-2023 06:03 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-24-2023 06:10 AM - edited 11-24-2023 06:12 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-24-2023 07:05 AM
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