- 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 07:36 AM
You're most welcome, glad it worked out 🙂
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-19-2024 01:38 PM
Can you share your working code?
I can't get a form created with glideModalForm to display a pre-set preference. I'm trying to set the state to "In use" and the assigned_to to the sc_task.requested_for but nothing seem to work.
ar af= new GlideModalForm('Update Asset JG','alm_asset');
af.setSysID(aTag);
af.addParm('sysparm_form_only', 'true'); //Remove related lists
af.setPreference('install_status','1'); //set state to in useSadly still shows "state" as In Stock:
Cheers
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-20-2024 02:33 AM
Hi @JGerrity ,
I would try and use the format mentioned by @-O-
In the example below it would be the set preference, sysparm_query line
ar af= new GlideModalForm('Update Asset JG','alm_asset');
af.setSysID(aTag);
//Line below to set the value of the state to In Progess
af.setPreference('sysparm_query', 'install_status=1');
af.addParm('sysparm_form_only', 'true'); //Remove related lists
Let me know how you get on
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-20-2024 05:12 AM
Hi @Matthew Knight ,
Thanks for getting back to me!
Unfortunately, I've tried that and when I do I get "Record not found" error. Commenting that line out at least brings up the record within the Modal.
I thought I'd try the same thing on the "comments" field to see if it had anything to do with State field being an integer field...same issue.
I also thought that the "comments" field from Dictionary Info is alm_hardware.comments so I tried that as my sysparm_query and still no luck (but at least it was able to render the asset within the modal, just not adding the comments.
Here are some screen shots if it helps:
Modal with "state" dictionary info:
Here is comments dictionary info:
Here's my full code, it:
- sets the currentUser variable from .requested_for
- Creates a modal promt to input asset tag
- Looks up asset tag sys_id from new glideRecord
- alerts (shows) value of asset tag and current user, just for my testing
- Creates glideModalForm modal of the alm_hardware table of the specific asset tag from first modal prompt Note: i've tried both alm_asset and alm_hardware tables, both get same results.
- I then try the setPreference('sysparm_query') lines for both state (install_status) and comments.
- If I use 'install_status' or 'comments' and not alm_hardware.install_status or alm_hardware.comments then it will result in record not found error.
You can see all the different combinations I've tried:
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_hardware');
af.setSysID(aTag);
// af.setPreference('sysparm_query','install_status=1'); //set state to in use
af.setPreference('sysparm_query', 'alm_hardware.install_status=1');
af.setPreference('sysparm_query','alm_hardware.comments=Hello Jason');
af.addParm('sysparm_form_only', 'true'); //Remove related lists
// af.setPreference('sysparm_query','install_status=In use'); //set state to in use
// af.setPreference('install_status','1'); //set state to in use
// af.setPreference('sysparm_query','comments=Hello Jason');
// af.setPreference('sys_id', aTag);
// g_form.setValue('alm_hardware.comments',value);
// af.setPreference('sysparm_query','comments=Some description');
// af.setPreference('assigned_to',currentUser);
// af.setPreference('sysparm_query','assigned_to='+currentUser);
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();
}What I'm trying to do is set "state" to "In use" and "assigned to" to requested_for of sc_task.
Any help would be greatly appreciated!
Cheers.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-20-2024 06:00 AM
Hi @JGerrity
What table is the Modal generating from?
Can you also send the full details of the UI Action, perhaps a screenshot of all the settings.
Many thanks
