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 03:08 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-20-2018 03:08 AM
Best way is to use glideajax for calling a script include and get value for manager. Below thread will be helpful
https://community.servicenow.com/community?id=community_question&sys_id=df864b25db1cdbc01dcaf3231f961904&view_source=searchResult
You can also try using display business rule to put the manager value in scratchpad and access the value in client script
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-20-2018 04:13 AM
Thats great, thanks.
Im very new to this so not done anything with script includes before. When I click 'client callable' it populates the script with this:
var getman = Class.create();
getman.prototype = Object.extendsObject(AbstractAjaxProcessor, {
type: 'getman'
});
Im not 100% sure what these means? do I just start coding on the thrid line?
EDIT: Also, in the example you provided they are trying to get the managers email, how do i get the managers name? is it somthing like gr.manager?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-20-2018 04:27 AM
For your question what it means, you can go through below link.
https://community.servicenow.com/community?id=community_question&sys_id=35500fa1db98dbc01dcaf3231f961909
You can create at line 3 and return the value to client script
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){
return user.sys_id;// returns manager's sys_id
}
},
type: 'getman'
});
