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

Jaspal Singh
Mega Patron
Mega Patron

Hi,

What is field type for u_application & u_grupa_administracyjna? Reference or free text field?

PawelBarcik_0-1699257938976.png

PawelBarcik_1-1699258008719.png

 

 

 

Hi @Pawel Barcik ,

 

What about u_application name field wht is the type of that?

For the other field can u try replacing the line

return service.u_grupa_administracyjna;

//with

return service.u_grupa_administracyjna.toString();

 

Thanks,

Danish

 

PawelBarcik_0-1699258648548.png