The CreatorCon Call for Content is officially open! Get started here.

scripts to check single line text against table

TMKAM
Tera Contributor

I have created Single line text in service catalog, and I have table 'trusted domain whitelisting".

Details as per below

 

Single line Text variable (u_domain_name)

table name = u_trusted_domain_whitelisting

Table Column 1 = u_active (True/False)

Table Column 2 = u_domain_whitelisting 

 

Here is scenario.

 

Scenario 1

When user enter a name in u_domain_name (variable), need to validate the domain name is existed or not in table "u_trusted_domain_whitelisting" and check if Table Column 1 = u_active (True) and it should check Table Column 2 = u_domain_whitelisting is existed if yes it need to show up an error message "Domain is available" and when user press "OK" it need to clear the u_domain_name (variable).

 

Scenario 2

When user enter a name in u_domain_name (variable), need to validate the domain name is existed or not in table "u_trusted_domain_whitelisting" and check if Table Column 1 = u_active (False) and it should skip check Table Column 2 = u_domain_whitelisting and nothing happen.

 

Please help me any one idea about this?

17 REPLIES 17

@TMKAM using gliderecord in client script is not recommended ..But for testing purpose you can try that..

TMKAM
Tera Contributor

Dear Maddysunil,

I have managed to get the client scripts and script included working as expected.

 

client scripts

function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var ga = new GlideAjax('checkDomainwhitelist');
ga.addParam('sysparm_name', 'validateDomain');
ga.addParam('sysparm_domain_name', newValue);
ga.getXMLAnswer(checkDomainExists);
}
 
function checkDomainExists(answer) {
if (answer == 'true') {
g_form.clearValue('u_domain_name');
//g_form.showFieldMsg('u_domain_name', 'This Domain Name already in the Whitelisting list, please enter the new Domain Name', 'error');
//g_form.addErrorMessage("This Domain Name already in the Whitelisting list, please enter the new Domain Name");
//g_form.addInfoMessage('This Domain Name already in the Whitelisting list, please enter the new Domain Name');
alert('This Domain Name already in the Whitelisting list, please enter the new Domain Name');
}
}
 
script include
var checkDomainwhitelist = Class.create();
checkDomainwhitelist.prototype = Object.extendsObject(AbstractAjaxProcessor, {
validateDomain: function() {
var domainName = this.getParameter('sysparm_domain_name');
var domainGR = new GlideRecord('u_trusted_domain_whitelisting');
domainGR.addQuery('u_domain_whitelisting', domainName);
domainGR.query();
if (domainGR.next()) {
return 'true';
} else {
return 'false';
}
},
type: 'checkDomainwhitelist'
});

@TMKAM 

Great! Happy to help you..

Kindly mark helpful/accepted if it helps you.

Thanks 

Sunil