Insert the Value of a field if it doesn't exists. if the value exists then create a new increment value which doesn't exists in a table field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-14-2022 09:00 AM
Hi Guys,
I have one use case -
I need to insert a value in a field 'class number' that needs to be unique. I need to check if the value already exists or not in a field 'class number' from the same table.
- if the new value doesn't exist then insert.
- If the duplicate is available for the new value then create a new increment value that is not duplicate
Did anyone face this kind of use case?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-14-2022 09:38 AM
Hello,
When the value exists, the field should be updated by incrementing the value.
For example we have a record that contains the value abc in the field class number
when we insert a new record that contain the same value in class number , so the field should be updated like this : abc 1 ?
Is that what you want ?
If it is no, you can only check Unique for field class number.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-14-2022 11:23 AM
The field can be incremented and updated to abc1 if the abc1 field value is not already present in the class number field.
If abc1 is already present then we need to once again increment to another value and check if it is present or not.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-15-2022 01:50 AM
Hello,
You can create a before business rule to get the number of records that have the same class number :
(function executeRule(current, previous /*null when async*/ ) {
var inc ="";
var record = new GlideRecord('incident');
record.addQuery("u_class_numberSTARTSWITH"+current.u_class_number);
record.query();
if (record.next()) {
inc = record.getRowCount();
current.u_class_number = current.u_class_number + "(" + inc + ")";
}
})(current, previous);
Here are some screen to see the results of the script :