Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

UI Action GlideModelForm passing values and callback

JGerrity
Tera Contributor

Hello Community,

Until we implement HAM, I'm trying to build a UI Action to assign an asset from an sc_task (Catalog task form).

I'm using a combination of a GlideModal "glide_prompt", to prompt for the asset tag along with a GlideModalForm to call the alm_hardware form.  I can get the initial prompt and a form to load, but not of the specific asset from the prompt.

My code so far is below, but my use case is:

  • From sc_task/catalog task form, agent clicks UI action
  • UI Action generates prompt to input asset tag
  • UI Action loads specific asset tag form (alm_hardware)
  • UI action sets state to "in use"
  • UI action sets assigned_to to value of sc_task.request_item.requested_for
  • UI action closes sc_task on submit of GlideModalForm.

Like I said, I can get the initial prompt, the loading of a new asset (not of specific) and I can set the state but can't seem to figure out what I'm missing to:

  1. load the specific asset form
  2. get the variable of sc_task.request_item.requested_for
  3. close the sc_task on callback.

Here's 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) {
	if (value!=""){
	var af= new GlideModalForm('Update Asset','alm_asset',''); //no callback yet
	var assetSID = value;
	af.setPreference('install_status',1) //set state to in use
	af.setPreference('asset_tag',assetSID);
	//af.setPreference('sys_id',assetSID);
	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();
}

 

Once I figure this out, my next question will be can you have two input boxes in the "glide_prompt" modal? I'd like to be able to scan for either asset tag or serial number, then use the input box who's value isn't =''

Thanks everyone!

2 REPLIES 2

Runjay Patel
Giga Sage

Hi @JGerrity ,

 

Check below thread, here i had gen working code. You  just need to do little modification on it.

https://www.servicenow.com/community/virtual-agent-forum/ui-action-to-assign-incidents-to-problem/m-...

 

-------------------------------------------------------------------------

If you found my response helpful, please consider selecting "Accept as Solution" and marking it as "Helpful." This not only supports me but also benefits the community.


Regards
Runjay Patel - ServiceNow Solution Architect
YouTube: https://www.youtube.com/@RunjayP
LinkedIn: https://www.linkedin.com/in/runjay

-------------------------------------------------------------------------

Hi @Runjay Patel ,


Thanks for the quick response, after reviewing your post I'm not sure it's what I'm looking for.  

You're using UI Pages with script includes.   I was hoping to contain everything within the UI Action client script.
Do you know how to reference a specific asset form view within glidmodalform?  I'm prompting for the asset_tag and want to show the form of that specific asset.

Cheers,
J.