Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

bacgrund script - don't work update date

Pawel Barcik
Mega Guru

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;
}

 

1 ACCEPTED SOLUTION

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

 

View solution in original post

9 REPLIES 9

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

 

PawelBarcik_0-1699258999308.png

😁Thanks 

 

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

 

Danish Bhairag2
Tera Sage

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

 

SANDEEP28
Mega Sage

@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 !!