Business Rule to Validate data of three Fields(Type Choice) to avoid Duplicate Entries

Tahzeeb
Giga Expert

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');

  1. newrec.addQuery('choicefile_one', current.choicefile_one);
  2. newrec.addQuery('choicefile_two', current.choicefile_two);
  3. 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 

  1. 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

1 ACCEPTED SOLUTION

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

Regards,
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.

View solution in original post

7 REPLIES 7

Pradeep Kumar7
Tera Contributor

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

 

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

Michael de Boer
Giga Guru

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

Regards,
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.

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"