In the below variable I need to show the incidents only which are requested by the logged in user an

Archana23
Tera Contributor

In the below variable I need to show the incidents only which are requested by the logged in user and the incidents which are raised on behalf of someone.

Please suggest .

Archana23_0-1717519649686.png

 

1 ACCEPTED SOLUTION

Hi @Archana23 

 

i have written the script not for the reference variable so i can check the code and will modify the code for reference variable 

 

 

thanks and regards 

Sai venkatesh 

View solution in original post

5 REPLIES 5

SAI VENKATESH
Tera Sage
Tera Sage

Hi @Archana23 

You can use the below code (client script and script include)

Client script:

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue === '') {
        return;
    }
    var categoryvalue = g_form.getValue('caller_id');
    var inci = new GlideAjax('incidentdetailsoftickets');
    inci.addParam('sysparm_name', 'getincidetails');
    inci.addParam('sysparm_category',categoryvalue);
    inci.getXMLAnswer(callback);

    function callback(response) {
        var answer = response;
		alert(answer);
		answer=answer.split(',');
		
		for(var i=0; i<answer.length;i++){
		g_form.addOption('u_incident_values',answer[i],answer[i]);
		}





    }

    //Type appropriate comment here, and begin script below

}

 

Script Include:

var incidentdetailsoftickets = Class.create();
incidentdetailsoftickets.prototype = Object.extendsObject(AbstractAjaxProcessor, {
	getincidetails: function() {
		//var calleridvalue=this.getParameter('sysparm_category');
        var incidentvalues = [];
        var incidentfetch = new GlideRecord('incident');
        incidentfetch.addQuery('caller_id',gs.getUserID());
        incidentfetch.query();
        while (incidentfetch.next()) {
            incidentvalues.push(incidentfetch.number.toString());
			gs.info("the valeus are "+incidentvalues);
        }
        return incidentvalues.toString();

    },

    type: 'incidentdetailsoftickets'
});

 It will create the values in the drop down (the incidents created by loggedin whose callerid is sameas loginuser) and it is working in my PDI

 

Thanks and regards

Sai Venkatesh

Hi @SAI VENKATESH ,

Thanks for your solution.

I am getting the incidents which are raised by me in the alert not in the variable.

 

Archana23_0-1717653656432.pngArchana23_1-1717653678763.png

 

Below are the client script and script include which I have replicated.

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue === '') {
        return;
    }
    var categoryvalue = g_form.getValue('caller_id');
    var inci = new GlideAjax('SE_Incidentdetails');
    inci.addParam('sysparm_name', 'getincidetails');
    inci.addParam('sysparm_category',categoryvalue);
    inci.getXMLAnswer(callback);

    function callback(response) {
        var answer = response;
        alert(answer);
        answer=answer.split(',');
       
        for(var i=0; i<answer.length;i++){
        g_form.addOption('enter_break_fix_incident_number',answer[i],answer[i]);
        }





    }

    //Type appropriate comment here, and begin script below

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

    getincidetails: function() {
        //var calleridvalue=this.getParameter('sysparm_category');
        var incidentvalues = [];
        var incidentfetch = new GlideRecord('incident');
        incidentfetch.addQuery('caller_id',gs.getUserID());
        incidentfetch.query();
        while (incidentfetch.next()) {
            incidentvalues.push(incidentfetch.number.toString());
            gs.info("the values are "+incidentvalues);
        }
        return incidentvalues.toString();

    },

   

    type: 'SE_Incidentdetails'
});

Client script

HI @Archana23 

 

What type of field are you using for that field ?

 

Thanks and Regards

Sai Venkatesh

I am using reference field and referring to incident table.