Need help getting data from location table to Catalog item
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-14-2020 09:23 AM
We are looking for some help with the Service Catalog and routing Catalog Tasks to groups.
I have Fields that were put on the Location table and trying to pull them into the Catalog Items.
We have been told we can only dotwalk 1 level on getting these Fields
“Since these 2 fields exist in the underlying table and not in user, using g_form.getReference you cannot access them.
The temporary and quick fix is to create 2 additional fields in user table and store this data for all users in those fields as well. Then you can access those fields like any other fields using getReference.”
I can pull them in with javascript but if user ID is changed then the update script will not work. Wondering if you have any ideas for how to handle this situation?
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-14-2020 12:19 PM
The Script Include:
var GetUserDetailsAjax = Class.create();
GetUserDetailsAjax.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getInfo: function(){
var obj={};
obj.location = '';
obj.pc_catalog = '';
obj.default_catalog = '';
obj.phone = '';
var id=this.getParameter('sysparm_user_id');
var gr= new GlideRecord('sys_user');
if(gr.get(id)){
obj.location = gr.location.name.toString();
obj.pc_catalog = gr.location.u_pc_catalog.toString();
obj.default_catalog = gr.location.u_catalog_default.toString();
obj.phone = gr.location.phone.toString();
}
return JSON.stringify(obj);
},
type: 'GetUserDetailsAjax'
});
Client Script:
function onChange(control, oldValue, newValue, isLoading) {
if (newValue == '') {
return;
}
var id = g_form.getValue('requested_by');
var ga = new GlideAjax('GetUserDetailsAjax');
ga.addParam('sysparm_name','getInfo');
ga.addParam('sysparm_user_id',id);
ga.getXML(CallBack);
function CallBack(response)
{
var answer = response.responseXML.documentElement.getAttribute("answer");
var user=JSON.parse(answer);
g_form.setValue('location',user.location);
g_form.setValue('pc_catalog',user.pc_catalog);
g_form.setValue('default_catalog',user.default_catalog);
g_form.setValue('phone',user.phone);
g_form.setReadOnly('location',true);
g_form.setReadOnly('pc_catalog',true);
g_form.setReadOnly('default_catalog',true);
g_form.setReadOnly('phone',true);
}
}
I did this work in a temp instance at https://dev74169.service-now.com/. Feel free to log in and take a look:
U/P = temp/12345
Links:
Script Include: https://dev74169.service-now.com/nav_to.do?uri=sys_script_include.do?sys_id=bf1b1a9edb5200103f156a49489619b6
Client Script: https://dev74169.service-now.com/nav_to.do?uri=catalog_script_client.do?sys_id=c32dde52db9200103f156a49489619cf
Catalog Item: https://dev74169.service-now.com/nav_to.do?uri=sc_cat_item.do?sys_id=a85b92dedb5200103f156a49489619ea
Catalog Item via Portal: https://dev74169.service-now.com/sp?id=sc_cat_item&sys_id=a85b92dedb5200103f156a49489619ea&sysparm_category=95fc11615f1211001c9b2572f2b477c6
I only updated users Abraham Lincoln and George Washington to have proper location values...
Please mark this as correct if this answers your question...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-14-2020 12:24 PM
Oh, and to add more fields, simply add them to the Script Include and the Client Script using the same syntax
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-14-2020 02:16 PM
Thanks I will look at it and let you know.
Thanks for the Much needed Help!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-14-2020 05:01 PM
Not sure what I'm doing wrong yet.
I can get them to Readonly but no data pulling over.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-14-2020 09:09 PM
Ok I got it to pull in the data. Its working Awesome..
Thanks for all your help!!