how to set the field value unique using script ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-21-2016 02:42 AM
Hi,
i have two fields X and Y,
if my X- field has a value "123" and Y - field has a value as "456"
then my Y field should not take any other value as "456" (for my X - field "123" ). it should throw an error as "record exist already".
Please help me out with using script.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-21-2016 02:57 AM
The values of X field and Y fields get stored in table when they submitted right ?
Then you can create an onchange client script and add error message if you check that table that X or Y field's value already exists.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-22-2016 12:57 AM
Business Rule for insert:
(function executeRule(current, previous /*null when async*/) {
// Add your code here
if (current.y &&
(current.operation() == "insert" ||
(current.operation() == "update" && current.y.changes()))) {
var gr = new GlideRecord("table_where_x_and_y_are");
gr.addQuery("y", current.y);
gr.query();
if (gr.getRowCount() > 0) {
current.setAbortAction(true);
gs.addErrorMessage(gs.getMessage("Not allowed the duplicate y=" + current.y));
}
}
})(current, previous);
--> replace y with your field value and you're done.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-22-2016 10:53 PM
Thanks for the response
i got the solution by writing a business rule.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-22-2016 11:22 PM
hi sarath. please mark as helpful and correct, if my answer helped. thanks