how to get owner name from CMDB table
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-27-2017 03:19 AM
Hi,
i have a requirement, by using variable value i have check the condition in cmdb_ci_service table after that i will get owner of service.but it won't working any help me
when i check the same script in background script ti is working at that time i have checked by using service name i am get owner name when i check by using variable value i won't worked
var gr=current.variables.test
alert(gr);// i got variable value in alert
var app=new GlideRecord("cmdb_ci_service");
app.addQuery("name", gr);
app.query();
if(gr.next());
{
var gr=app.u_owner;
}
above variable is list-collector. any help me.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-27-2017 07:14 AM
Hi ,
Yes it is provide the sys_id for that i used getDisplayValue(); at that time i was got name so that i am using Name in script.
list collector referred table is cmdb_ci_appl table.
for example i selected in the list collector value is sap. i called list collector value in variable "gr".
by using this variable i have check the condition in the table Cmdb_ci_service table.
condition:-
var gr=current.variables.test.toString();
gs.addInfoMeassge(gr);// i got variable value in alert
var app=new GlideRecord("cmdb_ci_service");
app.addQuery("nameSTARTWITH", gr);
app.query();
if(app.next());
{
var gr1 =app.u_owner; // it is custom filed
gs.addInfoMeassge(gr1);
}
BUT NO LUCK Can you any one help me
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-27-2017 07:22 AM
Use the below code.
var gr=current.variables.test.toString();
gs.addInfoMeassge(gr);// i got variable value in alert
var app=new GlideRecord("cmdb_ci");
app.addQuery("sys_id", gr);
app.query();
if(app.next());
{
var gr1 =app.u_owner.getDisplayValue(); // it is custom filed
gs.addInfoMeassge(gr1);
}
Instead of name use sys_id.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-28-2017 03:24 AM
it is not working.because the custom filed is coming thought cmdb_ci_service tables.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-28-2017 03:36 AM
Hi Shaik,
You code looks ok except Startwith. Try below code and let me know the result.
var gr=current.variables.test.toString();
var app=new GlideRecord("cmdb_ci_service");
app.addQuery("name", gr);
app.query();
if(app.next());
{
var gr1 =app.owned_by.getDisplayValue(); // it should work for custom field as well app.u_owner.getDisplayValue().
gs.log(gr1);
}
Hit like, Helpful or Correct depending on the impact of the response
Regards
Prashant
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-28-2017 04:51 AM
Hi Prashant,
condition is not meet because variable comes with cmdb_ci_appl table. by using this i will get the data cmdb_ci_service table.
for example
In cmdb_ci_appl record name is SAP but in cmdb_ci_service record is SAP WEB so that i will check STARTWITH in condition.
but it is working in background script here i checked record Name but i went by using variable value. can you please assist on that