- 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 08:10 AM
Hi Doug,
After running your script, instead of returning " ", I am getting "undefined" being returned. I know this is close, I'll continue to have a look into what's going on.
Thanks for your input,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-30-2014 08:14 AM
ok.. then what i would do is add a line to print the service name to verify it is finding the right service...
gs.print(service.name); //instead of .name put in the field name for the service name.. or any other service field you can see
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-30-2014 07:42 AM
The image below shows the element "managed_by", which I am trying in vain to retrieve from within a workflow.
If you scroll further, there are fields for name, and sys_id (which links back to the sys_users) table. Each script I have tried so far, has resulted in a variable equal to " " being returned?