- 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 06:03 AM
Hi Subhajit,
I don't want to retrieve a User Object, so the link is not relevant.
I'm only trying to retrieve the actual content of a field (managed_by) found within the 'cmdb_ci_service' table.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-30-2014 06:49 AM
the issue is that when the client is running the script you only have the sid for the service not the entire object and you need to retrieve the object from the database to the client... so the question becomes when is this script running? as a client side script on a request, etc.. or on the service catalog ...
if it is running on the service catalog you will just need to use the getReference method to retrieve the object; if it is running on a different area you will need to write a query like above to query the database to get the object and load it into a variable.. then you can get the manager by using var.manager.
it looks like this is probrably a workflow script so instead of
var service = current.variable_pool.srv_service; (Gives me the sys_id)
you would need
var service = new GlideRecord('cmdb_ci');
service.addQuery('sys_id', 'current.variable_pool.srv_service');
service.query()
while(service. next()){
var servname = service.getDisplayValue();
}
------
if that doesn't work try service.name.getDisplayValue();
if that fails the service may not be on the root cmdb_ci table and you will need to change the table from cmdb_ci to cmdb_ci_service or the appropriate table...
what i always do is run the query in a background script just hardcode the SID instead of using the variable.. and then add a line at the end gs.print(servname); to make sure the results are what you intend.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-30-2014 06:52 AM
Hi Ryan,
I dont think you can retrieve managed_by without getting the user object, since its a form variable, it will store only the sys_id and not object.
Regards,
Prakash

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-30-2014 07:02 AM
You'll need to read into the GlideRecord class on wiki.servicenow.com and look into the query section. A query primes the object you are looking for and allows you to do stuff with it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-30-2014 07:05 AM
Hi all,
Thanks for your input with this, but the issues still remains.
I need to retrieve the manager of a service. I have the service sys_id.
In the ('cmdb_ci_service') table, which I have used as a reference field within the form, there is a column for "managed_by" - this is the value I require.
It is stored as a 'sys_id' in the table.
I think I need to lookup the row containing the Service sys_id which I have, and return the sys_id of the "managed_by" column. Then, I'll need to query the sys_user table with the sys_id to get the managers name.
It just seem's overly complicated and longwinded for something so simple.