Look-up record from GlideModalForm
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-12-2024 08:14 AM - edited 11-12-2024 09:58 AM
Hello Community,
I am trying to create a UI Action that uses a GlideModalForm to display an asset from the alm_hardware or alm_asset table and allow updates to that asset.
My question is how to you take the input value from the modal and display the particular record in the form?
I can do the pop-up, but I can't load a specific asset into the form. How is this done? Do you use the setPreference('sysparam_query') method and if so, what is the query value for alm_hardware.asset_tag?
My code so far:
function scan_hardware(){
var gm = new GlideModal("glide_prompt", true, 600);
gm.setTitle("Scan Hardware");
gm.setPreference("title", "Asset Tag:");
gm.setPreference("onPromptComplete", function(value) {
var af= new GlideModalForm("Update Asset",'alm_asset');
var query = 'asset_tag' +value; //building the query string but I think this is the issue??
af.setPreference('syspram_query', query);
af.setPreference('install_status',1); //set state to in use
af.render();
});
gm.setPreference("onPromptCancel", function(value) {alert("You clicked on 'Cancel', value was: "+value)});
gm.render();
}
Thank you!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-12-2024 12:44 PM - edited 11-13-2024 06:29 AM
Thought I'd update myself.
Thanks to @ericgilmore for posting something that made me think in the right direction.
We need to find the sys_ID of the record from the modal prompt: (value is the variable name of the prior GlideModal"glide_prompt" I call earlier in below.)
var gr = new GlideRecord('alm_asset');
gr.addQuery('asset_tag', value);
gr.query();
if (gr.next()) {
var aTag = gr.sys_id;
}
Then you can use .setSysID to set the sys_ID and refer to that particular record:
var af= new GlideModalForm('Update Asset','alm_asset');
af.setSysID(aTag);
af.setPreference('alm_asset.install_status',1); //set state to in use
af.setPreference('alm_asset.assigned_to', currentUser);
af.render();
This now works and my GlideModalForm refers to the specific asset_tag. Thanks Eric!
Now I'm trying to set some field values in advance of the loaded asset form and I thought .setPreference was the way to achieve this, but it's not working...
af.setPreference('alm_asset.install_status',1); //set state to in use
af.setPreference('alm_asset.assigned_to', currentUser);
I've tried .setPreference('install_status',1) and 'state' but to no avail.
Thoughts anyone?
Cheers