validate if a value for a variable in the form exist in a table field

Bch
Tera Contributor

Hi, 

i am trying to build a change client script in a requested item to validate if the data in a specific field exist in field table.

in another word if the field A in the table = field B in the form. 

check if field C in the same table record contain field D in the form.

function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var Chkcity = g_form.GetValue('B');
var Chkczip = newValue ;  // field D
var Chkzip = new GlideRecord('Table name');
gr.addQuery("A", Chkcity);
gr.query();
if (gr.next()) {
if (gr.C.indexOf("Chkczip") ==-1);
{
alert("Please Enter a valid D.");
g_form.setValue("D","");
}
}
}

the script is giving a Error  (There is a JavaScript error in your browser console)

 

Thank you 

bch

2 REPLIES 2

Allen Andreas
Administrator
Administrator

Hi,

You have some formatting issues within this script and you're also using GlideRecord in a client script which is not appropriate or best practice. It's recommend to use GlideAjax to communicate with the server to check this information and then route that back to the client. Here's a cheat sheet for GlideAjax to assist with this: https://community.servicenow.com/community?id=community_article&sys_id=9f7ce2e1dbd0dbc01dcaf3231f961...

Please check that out and this for getting a field value using g_form: https://developer.servicenow.com/dev.do#!/learn/learning-plans/orlando/new_to_servicenow/app_store_l...

Please mark reply as Helpful/Correct, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

Hi,

I just wanted to check-in.

If my reply above helped guide you correctly, please mark as Correct.

Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!