Validate input field value

saurabhsharma
Giga Contributor

Hi 

I have created a custom table name as badge. I have two field name as Badge type and Bagde number. Badge type is of drop down has value C1 and C2 and Badge number is of text field. When user select type as C1 then user needs to enter value in number field. Suppose user enter A6857. Now when another user select C1 and enter same value that is A6857 then it should throw an error.

How can I validate this ? Kindly help me in this.

Thanks,

Saurabh

7 REPLIES 7

asifnoor
Kilo Patron

Before Insert BR on table badge

select advanced

in the script

var gr = new GlideRecord("badge");

gr.addQuery("badge_type",current.badge_type); //change the fields as per your names

gr.addQuery("badge_number",current.badge_number); //change the fields as per your names

gr.query();

if(gr.next()) {

gs.addErrorMessage("Same number cannot be sleected");

current.setAbortAction(true);

}

Mark the comment as a correct answer once worked.

Hi Asif,

Thanks for your response. I have applied this business rule but when I am entering next record it is throwing error for all records.

Thanks,

saurabh

Hi Saurabh,

The script basically checks and does not allow to enter a record if badge type and badge number (cobmination record) already exists.

If you do not want this, then let me know.