Verify banned words in catalog item variable(has regex) by storing banned words in custom table

Community Alums
Not applicable

Hi Everyone,

 

I am having requirement, where I have to validate banned words in variable (dl_name), banned words have stored in custom table name as ‘Banned words’ under ‘word’ column. And the variable has ‘Validation Regex’ i.e. ^DL_.*@snowmail.com$. 

Whenever in variable (dl_name) if user keep any word and if that word is listed in ‘Banned words’ custom table ‘word’ column then it should throw error message as ‘This word can not be used in distribution DL address’ and will not allow user to submit request. 

Ex. Banned words could be Horse, Tiger, Dog etc

dl_name = DL_Horse@snowmail.com     In that case it should not allow to submit and should throw error message.

 

 

I tried using onChange client script Glide ajax script include but In portal getting browser console error. If anyone came across any similar type of requirement please suggest me solution.

 

Thank you in advance!!!

 

 

1 ACCEPTED SOLUTION

Hey, Your script include can't have an initialise function (unless you also invoke the AbstractAjaxProcessor

var BannedWordsChecker = Class.create();
BannedWordsChecker.prototype = Object.extendsObject(AbstractAjaxProcessor, {

	checkBannedWords: function(){
		var inputName = String(this.getParameter('sysparm_dlName')).toLowerCase();
		if(!inputName)
			return 'NO_VALUE';
		
		var bannedWordsGR = new GlideRecord('u_banned_words');
		bannedWordsGR.query();
		while(bannedWordsGR.next()){
			var word = String(bannedWordsGR.getValue('u_word')).toLowerCase();

			if(inputName.contains(word))
				return true;
		}

		return false;
	},

    type: 'BannedWordsChecker'
});
function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }

    var dlName = newValue.toLowerCase(); // Convert to lowercase for case-insensitive comparison

    var ga = new GlideAjax('BannedWordsChecker');
    ga.addParam('sysparm_name', 'checkBannedWords');
    ga.addParam('sysparm_dlName', dlName);
    ga.getXMLAnswer(function(response) {

        if (response == null)
            console.error('Invalid Response');

        if (response == 'true')
            //Bad word foudn

            if (response == 'false')
                return;
    });
}

View solution in original post

5 REPLIES 5

Community Alums
Not applicable

It's giving error

ErrorThere is a JavaScript error in your browser console


getMessage (key="Quantity {0}"): synchronous use not supported in Mobile or Service Portal unless message is already cached
Unhandled exception in GlideAjax.