Unique field in cmdb_ci_service table

Nirav
Tera Expert

Hi,

 

I have a insert, update business rule which checks the uniqueness of the field "App ID" in "cmdb_ci_service" table. The table consist many different table and class like business application, infrastructure service, application instance.

 

I just want the business rule to check/compare "App id" in "Business application" and "Infrastructure service" class only and if similar "App id"  is found in this two then it should not allow insert or update of the record.

 

How do I achieve it please help?

 

Thanks.

 

unique app id.pngunique app id 2.png

 

business application.pnginfra service.png

1 ACCEPTED SOLUTION

Nirav
Tera Expert

I was able to resolve it by adding below code in the script. (line 2).

 

 

var ci=new GlideRecord('cmdb_ci_service');
ci.addQuery('sys_class_name', "cmdb_ci_service").addOrCondition('sys_class_name', "u_cmdb_ci_infra_service");
ci.addQuery('u_app_id',current.u_app_id);
ci.addQuery('sys_id','!=',current.sys_id);
ci.query();
if (ci.next()) {
current.setAbortAction(true);
gs.addErrorMessage('Duplicate App ID. APP ID already exists');
gs.addErrorMessage('Modify App ID and re-submit');
gs.log('Duplicate App ID: '+ current.u_app_id+' APP ID already exists');

}

View solution in original post

4 REPLIES 4

Sai Kumar B
Mega Sage
Mega Sage

@Nirav 

You can use the same filter conditions and try the following code

 

var checkDuplicates = new GlideRecord(current.getValue('sys_class_name')); //Glide to the current class
if(checkDuplicates.get('app_id', current.getValue('app_id')) { //Check the existing app_id records, if available do the following
current.setAbortAction(true); //Abort the action
gs.addErrorMessage("<Pass the error message>");
}

 

 

Hi Sai,

 

Thanks for the response. It is still not working. It is allowing me to enter the same "app id" field in the same class.

 

Does your scripts check in both "Business Application" and "Infrastructure Service" class? I want  BR to check in this two class only and if same App id is found it should abort and should show the error message.

 

Thanks.

 

 

 

Omkar Kumbhar
Mega Sage
Mega Sage

Hello @Nirav ,

You can wrtie and achieve this by writing 2 BRs one for class is business application glide record to cmdb_ci_service table and abort

Similarly,

You can write class is infrastructure service and gliderecord to cmdb_ci_infra_service and abort the action

If I was able to help you with your case, please click the Thumb Icon and mark as Correct.

Nirav
Tera Expert

I was able to resolve it by adding below code in the script. (line 2).

 

 

var ci=new GlideRecord('cmdb_ci_service');
ci.addQuery('sys_class_name', "cmdb_ci_service").addOrCondition('sys_class_name', "u_cmdb_ci_infra_service");
ci.addQuery('u_app_id',current.u_app_id);
ci.addQuery('sys_id','!=',current.sys_id);
ci.query();
if (ci.next()) {
current.setAbortAction(true);
gs.addErrorMessage('Duplicate App ID. APP ID already exists');
gs.addErrorMessage('Modify App ID and re-submit');
gs.log('Duplicate App ID: '+ current.u_app_id+' APP ID already exists');

}