Display an alert when a value is removed from list collector variable

Amit Rao
Giga Expert

Hello Experts,

 

We have a requirement to show an alert whenever values are removed from List collector variable.

 

Example: below is a variable of type list collector having ids in it.

so if ID -33524 is removed then it should show an alert ('Caution: you are removing this ID');

 

How can we achieve this requirement? 

1 ACCEPTED SOLUTION

piyushsain
Tera Guru
Tera Guru

Do this by calling Glide Ajax from the OnChange Client Script on the List Collector Variable.

 

var ga = new GlideAjax('GetData');
    ga.addParam('sysparm_name', 'getValueList');
    ga.addParam('sysparm_value', newValue);
    ga.addParam('sysparm_old_value', oldValue);
    ga.addParam('sysparm_table', 'tablename');//add the table name List Collector is refering to
    ga.getXML(ajaxResponse);
}

function ajaxResponse(serverResponse) {
    // Make all requested updates to the form
    var result = serverResponse.responseXML.getElementsByTagName('result');
    alert ('Caution: you are removing this ID ':result);

}

 

Script Include :

 

getValueList: function() {
    var table = this.getParameter('sysparm_table');
    var newValue = this.getParameter('sysparm_value');
    var oldValue = this.getParameter('sysparm_old_value');

    newValue = newValue.split(',');
    oldValue = oldValue.split(',');
    var arr = new ArrayUtil();
    var duplicatesRemoved = arr.diff(oldValue, newValue);
    var dispVal = [];
    for (var i in duplicatesRemoved) {
        var tableGR = new GlideRecord(table);
        tableGR.get(duplicatesRemoved[i]);
        dispVal.push(tableGR.name); // whatever field it is that you want to display
    }
    return dispVal;
},

 

If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.
Regards,
Piyush Sain

View solution in original post

2 REPLIES 2

Samaksh Wani
Giga Sage
Giga Sage

Hello @Amit Rao 

 

You need to write the below onChange Client Script :-

 

function onChange(control, oldValue, newValue, isLoading) {

alert("Caution: you are removing this" +oldvalue)

}

 

Plz mark my solution as Accept, If you find it helpful.

 

Regards,

Samaksh

 

 

 

piyushsain
Tera Guru
Tera Guru

Do this by calling Glide Ajax from the OnChange Client Script on the List Collector Variable.

 

var ga = new GlideAjax('GetData');
    ga.addParam('sysparm_name', 'getValueList');
    ga.addParam('sysparm_value', newValue);
    ga.addParam('sysparm_old_value', oldValue);
    ga.addParam('sysparm_table', 'tablename');//add the table name List Collector is refering to
    ga.getXML(ajaxResponse);
}

function ajaxResponse(serverResponse) {
    // Make all requested updates to the form
    var result = serverResponse.responseXML.getElementsByTagName('result');
    alert ('Caution: you are removing this ID ':result);

}

 

Script Include :

 

getValueList: function() {
    var table = this.getParameter('sysparm_table');
    var newValue = this.getParameter('sysparm_value');
    var oldValue = this.getParameter('sysparm_old_value');

    newValue = newValue.split(',');
    oldValue = oldValue.split(',');
    var arr = new ArrayUtil();
    var duplicatesRemoved = arr.diff(oldValue, newValue);
    var dispVal = [];
    for (var i in duplicatesRemoved) {
        var tableGR = new GlideRecord(table);
        tableGR.get(duplicatesRemoved[i]);
        dispVal.push(tableGR.name); // whatever field it is that you want to display
    }
    return dispVal;
},

 

If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.
Regards,
Piyush Sain