check Uniquess of a field in cmdb_ci_service table for specific class
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-03-2023 02:48 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 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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-04-2023 08:33 AM - edited 02-04-2023 08:38 AM
I use new field , typ string, with checked Calculated value. Then I just put in the script what should be this unique value - for ex.
return current.name + "_" + current.u_app_id;
This is one of the easiest ways to have a complex unique value (sum of A+B+X or somethig more - you can call even a script include if there is real need for that).
Note that you need to add the unique field on the Advanced view for that.
Note 2: Calculated values are not really saved! They are evaluated on record read, so be careful what you do there - dont do complex and too heavy operations as this will impact the performance (for ex. - dont call some heavy script include which in turn calls some REST ...that would tamper the overall performance)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-04-2023 03:28 PM
Hi Joro,
Thanks for the response. The script posted by me does work for uniqueness but the issue here I have is that currently the script looks for all the records classes in the whole table "cmdb_ci_service".
While what I need is that script should only search/compare for uniqueness in business application and infrastructure service class only. Sorry I am new to this can you help me with the scripts. Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-04-2023 03:36 PM
Hi Joro,
Thanks for the response. My posted scripts does work for the uniqueness for the field "App id" however the issue here I have is that the script is checking all the records of the cmdb_ci_service table.
What I need here is that the script should only search/check for uniqueness of the field only in business application and infrastructure class only. Can you please help me with the scripts as i am new to this. Thanks.