- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-28-2022 04:05 AM
Hello Experts,
We have a table which has three Choice FIelds > I need to write a Business Rule to validate if the data is already present to avoid duplicate entries.but somehow I am not able to retrieve the value of choice Fields.
Below is the code that I have tried
(function executeRule(current, previous /*null when async*/ ) {
// Add your code here
var newrec = new GlideRecord('custom_table');
- newrec.addQuery('choicefile_one', current.choicefile_one);
- newrec.addQuery('choicefile_two', current.choicefile_two);
- newrec.addQuery(' choicefile_three', current.choicefile_three);
newrec.query();
while (newrec.next()) {
gs.addErrorMessage("Duplicte Entry ");
current.setAbortAction(true);
}
})(current, previous);
I also tried to modify Lines 1,2,3 as
- newrec.addQuery('choicefile_one', current.choicefile_one.getDisplayValue());
But its not giving any Value
Tried to run the above script in background script but the value is showing as null.
Please suggest how this can be done
Regards,
TM
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-28-2022 04:59 AM
Try this:
(function executeRule(current, previous /*null when async*/ ) {
// Add your code here
var newrec = new GlideRecord('custom_table');
newrec.addQuery('choicefile_one', current.choicefile_one);
newrec.addQuery('choicefile_two', current.choicefile_two);
newrec.addQuery(' choicefile_three', current.choicefile_three);
newrec.query();
if (newrec.getRowCount() >= 1) {
gs.addErrorMessage("Duplicte Entry ");
current.setAbortAction(true);
}
})(current, previous);
Regards,
Michael
Michael
Please mark the suggestion as helpful/like, if you find it useful to you or others who wants to refer similar content.
Please mark the solution as correct, if the answer provided has resolved your query.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-28-2022 04:25 AM
Hi Tahzeeb,
Could you please confirm that what type BR are you using ? Also please check once the backend values of the current table choices match the custom table backend values. If required we can connect on this..
Regards,
Pradeep Kumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-28-2022 04:41 AM
Hi Pradeep,
its before Query BR on insert and update and all the backend values are same.
With the above code I am not even able to enter new entry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-28-2022 04:25 AM
What are the labels and values of the choices the same?
"current.choicefile_one" should contain the value of the choice not the label name.
And you run the BR on the custom table before insert & update?
Regards,
Michael
Michael
Please mark the suggestion as helpful/like, if you find it useful to you or others who wants to refer similar content.
Please mark the solution as correct, if the answer provided has resolved your query.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-28-2022 04:42 AM
I am referring in code the current.<backendfield name> which contains the Value entered from Menu choice.
The bR is Before Query on insert and Update.. With the above code I am not even able to enter new entry, there also I get the error as "Duplicate entry"