- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-30-2014 05:32 AM
Hi all
(I'm new to ServiceNow)
I have got a form that users complete to request a new account be created. I capture an business service chosen in the form, and then need to find the manager of that service.
At present, the following code saves the service chosen into a variable, which I can add to the description field.
var service = current.variable_pool.srv_service; (Gives me the sys_id)
var servname = service.getDisplayValue(); (Gives me the value of the "name" column for the above sys_id)
It has become apparent, that I now need to get the manager for the service. I have tried all below, with no success.
var man = service.managed_by;
var man = service.getElement('managed_by');
var man = service..managed_by.name;
I have also tried creating a glideRecord and querying the table ('cmdb_ci_service'), but again, no success. There is a column named "Managed By", in the 'cmdb_ci_service' table.
I'm sure it's something simple I'm missing?
Thanks,
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-30-2014 07:50 AM
Ryan thanks from that you can see that this field is on the cmdb_ci_service table... which is critical to querying to get it... so your script should be...
var service = new GlideRecord('cmdb_ci_service');
service.addQuery('sys_id', 'current.variable_pool.srv_service');
service.query()
while(service. next()){
var servname = service.managed_by.getDisplayValue();
}
i would run it as a background script by putting a SID for one of your services in where i have sid below.
var sid='sid';
var service = new GlideRecord('cmdb_ci');
service.addQuery('sys_id', sid);
service.query()
while(service. next()){
var servname = service.getDisplayValue();
gs.print(servname);
}
once you can retrieve the manager from a background script like this you are ready to put it in a workflow and replace the hardcoded sid with a variable name.. just take otu the gs.print command.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-30-2014 07:35 AM
Ryan is the managed by field a reference field for sys user?! if so the .getDisplayValue() method should work...
if not whichever table it is on you will need to either query to get the name .. or set the display value on that table.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-30-2014 07:07 AM
Hi,
Can you try below script:
var service = current.variables.srv_service;
var gr = new GlideRecord('cmdb_ci_service');
gr.get(service);
var man = gr.managed_by.getDisplayValue();
Please mark answer as correct/helpful, if it was really helpful 🙂
Regards,
Solutioner
Enhance Knowledge NOW@ www.solutioningnow.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-30-2014 07:39 AM
Hi solutioner_now,
Your script returns an empty variable, as in " ";
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-30-2014 07:44 AM
Hi Ryan,
Can you just confirm the field names. I tired similar script for different field in demo005 and its giving proper value, I'm pasting the reference script:
var dept = current.variables.depart;
var gr = new GlideRecord('cmn_department');
gr.get(dept);
gs.addInfoMessage(gr.dept_head.getDisplayValue())
Please mark answer as correct/helpful, if it was really helpful 🙂
Regards,
Solutioner
Enhance Knowledge NOW@ www.solutioningnow.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-30-2014 07:50 AM
Ryan thanks from that you can see that this field is on the cmdb_ci_service table... which is critical to querying to get it... so your script should be...
var service = new GlideRecord('cmdb_ci_service');
service.addQuery('sys_id', 'current.variable_pool.srv_service');
service.query()
while(service. next()){
var servname = service.managed_by.getDisplayValue();
}
i would run it as a background script by putting a SID for one of your services in where i have sid below.
var sid='sid';
var service = new GlideRecord('cmdb_ci');
service.addQuery('sys_id', sid);
service.query()
while(service. next()){
var servname = service.getDisplayValue();
gs.print(servname);
}
once you can retrieve the manager from a background script like this you are ready to put it in a workflow and replace the hardcoded sid with a variable name.. just take otu the gs.print command.