- 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-20-2024 06:54 AM - edited 11-20-2024 06:55 AM
Hi @Matthew Knight ,
I wonder if we should be starting a separate thread LOL
The modal is generating from alm_hardware table, unless you mean where is the UI Action generating from then, that is the sc_task table.
var af= new GlideModalForm('Update Asset','alm_hardware');
...
af.render();
Here is the full details (screen shot) of my UI Action:
Cheers!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-20-2024 08:39 AM - edited 11-20-2024 08:44 AM
Wrong account
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-20-2024 08:46 AM - edited 11-21-2024 08:21 AM
@JGerrityyour case is different from the one described in the original post. You want to load an existing record and modify it.
I can see two ways to do it:
1. add some custom URL parameter and intercept it in a display business rule and apply modifications to the loaded record
2. add to your script (of course setPreference is not needed) something like:
var aTag = '...'
var af = new GlideModalForm('Update Asset JG', 'alm_asset');
af.setSysID(aTag);
af.addParm('sysparm_form_only', 'true');
af.setOnloadCallback(onAssetModalLoadCallback());
af.render();
function onAssetModalLoadCallback() {
return function() {
var childGForm = window.frames['dialog_frame'].g_form;
childGForm.setValue('install_status', '1');
};
}
Of course through childGForm you can interact with the loaded form the same as you would interact with any form through g_form.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-20-2024 10:21 AM - edited 11-20-2024 10:45 AM
Hi @-O- ,
Thanks for jumping in here.
That's a creative approach with childGForm but unfortunately, that doesn't seem to work either.
Here is my code:
function scanHardware(){
var currentUser = g_form.getValue('sc_task.request_item.requested_for');
var gm = new GlideModal("glide_prompt", true, 600);
gm.setTitle("Scan Hardware");
gm.setPreference("title", "Asset Tag:");
gm.setPreference("onPromptComplete", function(value) {
if (value!=""){
var gr = new GlideRecord('alm_asset');
gr.addQuery('asset_tag', value);
gr.query();
if (gr.next()) {
var aTag = gr.sys_id;
}
alert(currentUser+"AssetTag="+aTag);
var af= new GlideModalForm('Update Asset','alm_asset');
af.setSysID(aTag);
af.addParm('sysparm_form_only', 'true');
af.setOnloadCallback(onAssetModalLoadCallback());
af.render();
}else{
alert("you didn't enter a value!");
}
});
gm.setPreference("onPromptCancel", function(value) {alert("You clicked on 'Cancel', value was: "+value)});
gm.render();
}
function onAssetModalLoadCallback() {
return function() {
var childGForm = window.frames['dialog_frame'].g_form;
childGForm.setValue('install_status', '1');
childGForm.setValue('comments', 'Hi Jason');
};
}
But the record loaded into the modal isn't getting modified:
Thanks again everyone for your help!
J.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-20-2024 02:41 PM - edited 11-20-2024 02:48 PM
You may need to replace window with top or self. I'm suspecting the code is executed in a "protected"/isolated context.
Where does all this code reside?
For me, when executed form the browser console, the code works as expected.
