trying to builup a catalog item using script include

samreenayesha
Tera Contributor

trying to buildup a catalog item using script include where when user put the value for example "serial number" it will give the error that serial number is already exist writing client callable script but stuck to build up a logic any help ?

3 REPLIES 3

Anurag Tripathi
Mega Patron
Mega Patron

Try this

 

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }
    try {
        var ajax = new GlideAjax('<script include>');
        ajax.addParam('sysparm_name', '<function name>');
        ajax.addParam('sysparm_rec_name', newValue);
        ajax.getXMLAnswer(function(answer) {
            if (answer == true) {
            //clear value
//throw error
            }
        });
    } catch (e) {
        alert(e.message);
    }
}

Script Include:

var <SCript include NAme>= Class.create();
<SCript include NAme>.prototype = Object.extendsObject(AbstractAjaxProcessor, {
    <function NAme>: function() {
        var groupName = this.getParameter('sysparm_re_name');
        var grGroup = new GlideRecord('<table>');
        if (grGroup.get('name', groupName)) {
            return true;
        }
        return false;
    },
    type: 'GroupUtil'
});

 

 

Use correct script include, table and function names

-Anurag

in script include what is 'name ' indicating

You need to give the script a name

It could be anything like CalaogItemSupportUtil

 

The name in line below is just indicative, you need to build that query based on your logic whatever way you identify whether record exists or not

if (grGroup.get('name', groupName)) {

-Anurag