populate message if selected user is "inactive" from list field on the form

lakshmi_laksh
Tera Contributor

Hello,
i have a requirement , if the selected user is "Inactive" from list datatype field then message should be displayed saying "selected user is inactive (along with name of the selected user)". using script include and client script
the "Member list" Refers to "sys_user" table.
Thanks in advance

lakshmi_laksh_0-1714719554185.png

 






4 REPLIES 4

Community Alums
Not applicable

Hi @lakshmi_laksh ,

I tried your problem in my PDI and it works for me please refer below code 

Create OnSubmit Client script and add below code 

function onSubmit() {
   //Type appropriate comment here, and begin script below
   alert("watch List = " + g_form.getValue("watch_list"));
    var ga = new GlideAjax('getUserWatchList');
    ga.addParam('sysparm_name', 'userHandler');
    ga.addParam('sysparm_watchList', g_form.getValue("watch_list"));
    ga.getXML(updateCampus);

    function updateCampus(response) {
        var answer = response.responseXML.documentElement.getAttribute("answer");
        alert('answer = ' + answer);
		if(answer == false || answer == 'false'){
			alert('User selected is inactive ');
		}
    }
}

Create Script include which is client callable and add below code 

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

	userHandler: function(){
		gs.log('here');
		var watchList = this.getParameter('sysparm_watchList');
		gs.log('watchList = ' + watchList);
		var userGr = new GlideRecord('sys_user');
		userGr.addQuery('sys_idIN'+ watchList);
		userGr.query();
		while(userGr.next()){
			gs.log("Inside while  ");
			if(userGr.active == false){
				return false;
				
			}
		}
	},

    type: 'getUserWatchList'
});

 

Please mark my answer correct and helpful if this works for you

 

Thanks and Regards 

Sarthak

Community Alums
Not applicable

Hi @lakshmi_laksh ,

Is my answer helps you? 

 

If this helps if mark my answer correct and helpful if this works for you

Thanks and Regards 

Sarthak

Jitendra Diwak1
Kilo Sage

Hi @lakshmi_laksh 

 

For this query, I created one field(List) on Incident table and applied onChange client script which is given below:

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

   //Type appropriate comment here, and begin script below
   var ga = new GlideAjax('AlertUser');
    ga.addParam('sysparm_name', 'alerUserForInactive');
    ga.addParam('sysparm_users_sys_id', g_form.getValue("u_member"));
    ga.getXML(callBack);

    function callBack(response) {
        var answer = response.responseXML.documentElement.getAttribute("answer");
        if(answer == 'false' ){
            alert('Inactive use has been selected.');
        }
    }
}
 
And Create one script include which is given below:
var AlertUser = Class.create();
AlertUser.prototype = Object.extendsObject(AbstractAjaxProcessor, {

    alerUserForInactive: function(){
        gs.log('here');
        var user_sys_id = this.getParameter('sysparm_users_sys_id');
        var userGr = new GlideRecord('sys_user');
        userGr.addQuery('sys_idIN'+ user_sys_id);
        userGr.query();
        while(userGr.next()){
            if(userGr.active == false){
                return false;
               
            }
        }
    },

    type: 'AlertUser'
});
 
make sure that your script include is client callable and there is one field client callable as true. I am attaching the one screenshot for the reference.
 
Thanks
Jitendra
Please accept my solution if it works for and thumps up.

Jitendra Diwak1
Kilo Sage

Hi @lakshmi_laksh,

 

If this helps please mark my answer correct and helpful if this works for you.

 

Thanks

Jitendra

Please accept my solution if it works for and thumps up.