Query in client script?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-20-2018 02:47 AM
Hi
I have an onchange client script which auto fills fields depending on the person who is logged in and what catergerys are seleceted:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
if (g_form.getValue('u_subcategory') == 'New' && g_form.getValue('u_category') == 'Certificate') {
g_form.setValue('u_requested_by',g_user.userID) ;
g_form.setValue('short_description','New Certificate Request');
g_form.setValue('description','Certificate name:\r\nCertificate Type (SSL, SSL with EV, Wildcard, Code signing):\r\nCertificate Term:\r\nServer Software:\r\nRegion if applicable (EMEA, ASPAC,US etc)\n\n');
}
I have got it to fill in a field depending on the user (g_user.userID) but I would also like it to fill in the users manager. I dont beleive I can use g_user for this and have to query the sys_user table? I am new to scripting and im not sure how I would encorperate a query into this script.
Any suggestions would be much appreciated.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-20-2018 05:33 AM
can you post your current script?
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-20-2018 05:40 AM
Client Script:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
if (g_form.getValue('u_subcategory') == 'New' && g_form.getValue('u_category') == 'Certificate') {
var ga = new GlideAjax('getManager') ;
ga.addParam('sysparm_name','getManager');
ga.addParam('sysparm_id', g_user.userID);
ga.getXMLAnswer(function(response){
alert(response);
});
g_form.setValue('u_requested_by',g_user.userID) ;
g_form.setValue('short_description','New Certificate Request');
g_form.setValue('description','Certificate name:\r\nCertificate Type (SSL, SSL with EV, Wildcard, Code signing):\r\nCertificate Term:\r\nServer Software:\r\nRegion if applicable (EMEA, ASPAC,US etc)\n\n');
}
Script include:
var getman= Class.create();
getman.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getManager: function(){
var id = this.getParameter('sysparm_id'); //get user_id passed from client script
var user = new GlideRecord('sys_user');
user.get('user_name',id);
if (user){
user.getValue('manager');// returns manager's sys_id
}
},
type: 'getman'
});
the results of the script include should go into the 'assigned_to' field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-20-2018 05:44 AM
your script include name is incorrect. "getman" is the name of the script include right?
var ga = new GlideAjax('getman') ;
ga.addParam('sysparm_name','getManager');
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-20-2018 05:53 AM
Of course! Its now bringing up the message box but its still 'null' So I assume its not pulling back the manager name? Is user.getValue('manager'); Correct for the script include?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-20-2018 05:54 AM
Sorry
Remember that your response is in a function and when you get your reponse you can then do specific logic when used inside the function
In your script include remember to "return user.getValue('manager');"
Not just user.getValue('manager');
if (g_form.getValue('u_subcategory') == 'New' && g_form.getValue('u_category') == 'Certificate') {
var ga = new GlideAjax('getman') ;
ga.addParam('sysparm_name','getManager');
ga.addParam('sysparm_id', g_user.userID);
ga.getXMLAnswer(function(response){
alert(response);
g_form.setValue('u_requested_by',g_user.userID);
g_form.setValue('short_description','New Certificate Request');
g_form.setValue('description','Certificate name:\r\nCertificate Type (SSL, SSL with EV, Wildcard, Code signing):\r\nCertificate Term:\r\nServer Software:\r\nRegion if applicable (EMEA, ASPAC,US etc)\n\n');
});
}
