Get name of catalog item in catalog client script

pat222
Tera Expert

Hello,

I need to get the name of the catalog item where the catalog client script is execuded.

Is there any way to do this without g_form.getParameter("sysparm_id") and than querying the name with the sysId?

Thanks,

Patrick

1 ACCEPTED SOLUTION

Michael Jones -
Giga Sage

There isn't a "simple" way to do this, no, at least not that I've found. Depending on your requirements there are a couple of ways you could do it.

As a heads up, g_form.getParameter() doesn't work in the ServicePortal. If you need this to work in the ServicePortal, you would need to use g_form.getUniqueValue(), which will return the sys_id of the item. 

Once you have the sys_id you would need to use GlideAjax to make the call server-side to return the name of the item. If you tried a straight GlideRecord it might work for an admin, but wouldn't work for a user. 

If you need to do this dynamically across a lot of catalog items your best bet is probably to use the client script / GlideAjax approach.

If you only need this for a specific item or two, you could add a variable to the form (single line text), hide the variable, and then for the default value use: 

javascript:current.cat_item

Then, when you needed the name of the item, you could call the value of your hidden variable. 

Hope this helps!

If this was helpful or correct, please be kind and click appropriately!

Michael Jones - Proud member of the CloudPires Team!

I hope this helps!
Michael D. Jones
Proud member of the GlideFast Consulting Team!

View solution in original post

1 REPLY 1

Michael Jones -
Giga Sage

There isn't a "simple" way to do this, no, at least not that I've found. Depending on your requirements there are a couple of ways you could do it.

As a heads up, g_form.getParameter() doesn't work in the ServicePortal. If you need this to work in the ServicePortal, you would need to use g_form.getUniqueValue(), which will return the sys_id of the item. 

Once you have the sys_id you would need to use GlideAjax to make the call server-side to return the name of the item. If you tried a straight GlideRecord it might work for an admin, but wouldn't work for a user. 

If you need to do this dynamically across a lot of catalog items your best bet is probably to use the client script / GlideAjax approach.

If you only need this for a specific item or two, you could add a variable to the form (single line text), hide the variable, and then for the default value use: 

javascript:current.cat_item

Then, when you needed the name of the item, you could call the value of your hidden variable. 

Hope this helps!

If this was helpful or correct, please be kind and click appropriately!

Michael Jones - Proud member of the CloudPires Team!

I hope this helps!
Michael D. Jones
Proud member of the GlideFast Consulting Team!