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-20-2020 07:02 AM
I assume that "u_glide_list_1" is a reference field on the catalog item, if it is pulling SYS_ID.
I am going to further assume that the field you want to pull is "name" from this reference field.
If so, update your 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 = '';
obj.name = ''; //THIS IS THE NEW "NAME" OBJECT SET NULL
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();
obj.name = gr.location.u_glide_list_1.name.toString(); // THIS IS NEW "NAME" OBJECT AS DEFINED BY THE GLIDE RECORD...NAME VALUE IS DOT-WALKED
}
return JSON.stringify(obj);
},
type: 'GetUserDetailsAjax'
});
Next, update your 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.setValue('<<VARIABLE FIELD NAME>>',user.name); //THIS IS THE NEW "NAME" OBJECT POPULATING THE FIELD. I AM NOT SURE WHAT YOUR VARIABLE NAME IS ON THE CATALOG ITEM
g_form.setReadOnly('location',true);
g_form.setReadOnly('pc_catalog',true);
g_form.setReadOnly('default_catalog',true);
g_form.setReadOnly('phone',true);
g_form.setReadOnly('<<VARIABLE FIELD NAME>>',true); //AND WE MAKE THAT FIELD READ-ONLY AS WELL
}
}
hope this helps... you will have to pardon my assumptions as i cannot see your tables and custom fields...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-20-2020 11:26 AM
Thanks again..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-20-2020 12:21 PM
u_glide_list_1 is a field on the location table named FOG
We are trying to get that into the catalog item.
Hope that helps
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-31-2020 11:15 AM
any suggestions for that last part? it comes up undefined.