Built something you're proud of? Tell the story. A quick G2 review of App Engine or Build Agent helps other developers see what's possible on ServiceNow. Share your experience.

How to Check the unique value in the Catalog variables

Vamshi Krishna2
Tera Contributor

Hi Experts,

I have 5 catalog variables type is single line text, User will manually give the input to all this 5 variables but all should be unique and not match with each other. if user giving same value in all this or any of this is matching with one another then i need to restrict submitting the request. How to restrict is there any onsubmit client script?

 

Thanks in advance

2 REPLIES 2

Raghav Sharma24
Giga Patron

You need to write an on submit client script:

 

if(g_form.getValue('var1')==g_form.getValue('var2')||g_form.getValue('var1')==g_form.getValue('var3')) // add more OR conditions

{

return false;

}

else if(g_form.getValue('var2')==g_form.getValue('var3')||g_form.getValue('var2')==g_form.getValue('var4'))

{

return false

}

 

do it till your last variable and it should work, the last condition will only contain below:

else if(g_form.getValue('var5')==g_form.getValue('var4'))  // as all other conditions have already been checked in above for loops

{

return false;

}

Omkar Kadoli
Tera Contributor

Hi @Vamshi Krishna2 ,

You need to write an on submit catalog client script:

 

function onSubmit() {
var var1 = g_form.getValue('variable1');
var var2 = g_form.getValue('variable2');
var var3 = g_form.getValue('variable3');
var var4 = g_form.getValue('variable4');
var var5 = g_form.getValue('variable5');

if (var1 === var2 ) {
g_form.addErrorMessage("Please Dont enter same value …………. ");
}
if (var2 === var3 ) {
g_form.addErrorMessage("Please Dont enter same value …………. ");
}
if (var3 === var4 ) {
g_form.addErrorMessage("Please Dont enter same value …………. ");
}
if (var4 === var5) {
g_form.addErrorMessage("Please Dont enter same value …………. ");
}
if (var5 === var1) {
g_form.addErrorMessage("Please Enter the Value Variable5 …………. ");
}
if (var5 === var3) {
g_form.addErrorMessage("Please Dont enter same value …………. ");
}
if (var5 === var2) {
g_form.addErrorMessage("Please Dont enter same value …………. ");
}
if (var4 === var2) {
g_form.addErrorMessage("Please Dont enter same value …………. ");
}
if (var4 === var1) {
g_form.addErrorMessage("Please Dont enter same value …………. ");
}
if (var3 === var1) {
g_form.addErrorMessage("Please Dont enter same value …………. ");
}
if (var3 === var5) {
g_form.addErrorMessage("Please Dont enter same value …………. ");
}
if (var2 === var4) {
g_form.addErrorMessage("Please Dont enter same value …………. ");
}
if (var2 === var5) {
g_form.addErrorMessage("Please Dont enter same value …………. ");
}

}

 

Thanks,

Omkar