- 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-21-2024 04:43 AM
Hi @-O- ,
Replacing window with self worked. It initially presents the modal unchanged, but then flashes to the new values of the setValue lines.
Not sure I understand where does this code resides? It's all within a UI Action, on the sc_task table. I'll also look into what protected/isolated context might mean.
Thanks a lot for your assistance!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-21-2024 08:19 AM
The delay in updating the field is most likely due to the fact that the code is executed after the form "settles" which - as we have all experienced - usually takes a few seconds.
By protected/isolated I mean the "Isolate script" checkbox on certain script artifacts, like in UI Actions, or Client Scripts, a.s.o. When checked certain global objects (like window) are shadowed and not available.
And you're welcome 🙂
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-21-2024 09:29 AM
Hi @-O-
Thank you again for your help!! It is/was greatly appreciated and I now have it working.
I assume that since this is all under the reply thread I can't mark yours as correct answer... sorry about that.
My last (honest LOL) question is I'd like to set the assigned_to on the modal form to the requested_for of the orginating sc_task.
However, when I'm trying to get the value of the requested_for field it returns the SCTasknumber for some reason??
Here's my code to get sc_tasks requested for (which shows SCTASK100223 )
var currentUser = g_form.getDisplayValue('sc_task.request_item.requested_for');
alert(currentUser);
Thanks again and honest no more questions 🙂
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-21-2024 02:30 PM - edited 11-21-2024 02:32 PM
Arbitrary dot-walking is not possible client side.
Also while server side <GlideRecord>.getDisplayValue() has two forms:
- with no parameters it returns the display value of the record
- with one parameter it returns the display value of the field - the parameter
at the same time g_form.getDisplayValue() has just one form: it returns the current record's display value (ignores any parameters) - hence the Catalog Task number shown.
Client side if you need some display value, you need to GlideAjax for it.
That said assigned_to does not need a display value, but a value and you can get that if you add the dot-walked field to the form (or GlideAjax for it).
If you add the dot-walked "request_item.requested_for" field to the form, then you can get the value using command
g_form.getValue('request_item.requested_for');
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-22-2024 05:46 AM
Hi @-O- ,
Thank you for explaining the details of dot-walking. It was just as simple as changing my original code (I had originally used .getValue and not .getDisplayValue but I was using the incorrect dot-walk. (I was looking at the Dictionary info for "Requested for" on the SCTask which showed it as sc_task.request_item.requested_for). Chaning my .getValue to request_item.requested_for worked!
var currentUser = g_form.getValue('request_item.requested_for');
Thank you again for all your help!
***Marked as correct answer*** 😁
