- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-05-2023 11:57 PM
I don't know why it doesn't want to be done
var database = new GlideRecord('cmdb_ci_database');
database.query();
// I go through the database and get the application name
// if the application field is not empty, it will execute the contents of if
// I get the value from cmdb_ci_service by what the function returns, if it is not empty, I enter it into the DATABASE)
while (database.next()){
var applicationName = database.u_application;
if(applicationName !== null)
{
var adminGroup = getAdminGroup(applicationName);
if(adminGroup !== null)
{
database.support_group=adminGroup;
database.update();
}
}
}
function getAdminGroup(applicationName)
{
var service = new GlideRecord('cmdb_ci_service');
service.addQuery('name',applicationName);
service.query();
if (service.next()){
return service.u_grupa_administracyjna;
}
return null;
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-06-2023 12:19 AM
Hi @Pawel Barcik ,
Can u try the below code please:
var database = new GlideRecord('cmdb_ci_database');
database.query();
// I go through the database and get the application name
// if the application field is not empty, it will execute the contents of if
// I get the value from cmdb_ci_service by what the function returns, if it is not empty, I enter it into the DATABASE)
while (database.next()){
var applicationName = database.u_application;
if(applicationName !== null)
{
var adminGroup = getAdminGroup(applicationName);
if(adminGroup !== null)
{
database.support_group=adminGroup;
database.update();
}
}
}
function getAdminGroup(applicationName)
{
var service = new GlideRecord('cmdb_ci_service');
service.addQuery('sys_id',applicationName);
service.query();
if (service.next()){
return service.u_grupa_administracyjna.toString();
}
return null;
}
Thanks,
Danish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-06-2023 12:19 AM
Hi @Pawel Barcik ,
Can u try the below code please:
var database = new GlideRecord('cmdb_ci_database');
database.query();
// I go through the database and get the application name
// if the application field is not empty, it will execute the contents of if
// I get the value from cmdb_ci_service by what the function returns, if it is not empty, I enter it into the DATABASE)
while (database.next()){
var applicationName = database.u_application;
if(applicationName !== null)
{
var adminGroup = getAdminGroup(applicationName);
if(adminGroup !== null)
{
database.support_group=adminGroup;
database.update();
}
}
}
function getAdminGroup(applicationName)
{
var service = new GlideRecord('cmdb_ci_service');
service.addQuery('sys_id',applicationName);
service.query();
if (service.next()){
return service.u_grupa_administracyjna.toString();
}
return null;
}
Thanks,
Danish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-06-2023 12:23 AM
😁Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-06-2023 12:25 AM - edited 11-06-2023 12:25 AM
Hi @Pawel Barcik ,
Great to see. Could you please mark my response as helpful & accepted if it helped you resolve your issue, so that others can find the right answer.
Thanks,
Danish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-06-2023 12:06 AM
Hi @Pawel Barcik ,
if your field u_application is reference type then the below block will not execute as u r trying to filter with name.
function getAdminGroup(applicationName)
{
var service = new GlideRecord('cmdb_ci_service');
service.addQuery('name',applicationName); // if field is not reference type then valid else not valid
service.query();
if (service.next()){
return service.u_grupa_administracyjna;
}
return null;
}
Thanks,
Danish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-06-2023 12:25 AM
@Pawel Barcik Try below code
var database = new GlideRecord('cmdb_ci_database');
database.query();
// I go through the database and get the application name
// if the application field is not empty, it will execute the contents of if
// I get the value from cmdb_ci_service by what the function returns, if it is not empty, I enter it into the DATABASE)
while (database.next()){
var applicationName = database.u_application;
if(applicationName !== null)
{
var adminGroup = getAdminGroup(applicationName);
if(adminGroup !== null)
{
database.support_group=adminGroup;
database.update();
}
}
}
function getAdminGroup(applicationName)
{
var service = new GlideRecord('cmdb_ci_service');
if (service.get(applicationName))
return service.u_grupa_administracyjna; // check this u_grupa_administracyjna field name is proper or not
else
return null;
}
If I could help you with your Query then, please hit the Thumb Icon and mark as Correct !!
