- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-03-2023 02:36 PM
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.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-10-2023 08:30 AM
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');
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-05-2023 06:14 AM - edited 02-05-2023 06:14 AM
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>");
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-05-2023 03:47 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-06-2023 03:42 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-10-2023 08:30 AM
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');
}