ITSM Interview Questions and Answers with scenarios

shubhamdubey
Mega Sage
1. In the incident form , if user select any assignment group and that assignment group 
Does not have any member available then user is not able to submit/update the form.
 
Ans  :- Before BR 
    (function executeRule(current, previous /*null when async*/) {
 
// Add your code here
 
var gr = new GlideRecord('sys_user_grmember');

gr.addQuery('group' ,current.assignment_group);

gr.query();

if(!gr.next()){

gs.addErrorMessage("dont have any user in this group");

current.setAbortAction(true);

}

})(current, previous);

2. Create a script include named test and create 2 functions on it named in fn1() and f2().
   In fn2() create 2 variables first_name and last_name and assign some value to them and print
those values in background script by calling in fun1 function.
 
Ans :- Script Include
 
  var Test = Class.create();
Test.prototype = {

    initialize: function() {

    },
    fun1: function(){

return this.fun2();

},

fun2: function(){

var obj = {};

obj.first_name = "shubham" ;

obj.last_name = "Dubey" ;

return JSON.stringify(obj);

},

    type: 'Test'

};

Background Script :- 

var gr = new Test();

var gr1 = gr.fun1();

  var ans = JSON.parse(gr1);

gs.addInfoMessage(ans.first_name);

gs.addInfoMessage(ans.last_name);

3. In incident form can you check whether caller is vip or not whithout using getReference() method in client script or script includes.
 
 ANS :- 
   Business rule :- 

   (function execute Rule(current, previous /*null when async*/) {
// Add your code here

g_scratchpad.VIP = current.caller_id.vip;

g_scratchpad.managerName = current.caller_id.manager.getDisplayValue();
})(current, previous);

Client Script :- 

    function onLoad() {

    //Type appropriate comment here, and begin script below

    if (g_scratchpad.VIP == "true") {

        alert("caller is VIP"+"manager name = " + g_scratchpad.managerName);

    } else {

        alert("caller is not VIP");

    }


}  
4. Find out the records on behalf of group by category
 
var ga = new GlideAggregate('incident');

ga.addAggregate('COUNT');

ga.groupBy('category');

ga.query();

while(ga.next()){

var count = ga.getAggregate('COUNT');

var gr =  ga.getDisplayValue('category');

gs.info(count + " " + gr);

}
5. Find out the caller is VIP or not with the help of client script?
 
Onchange client script:-

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

    if (isLoading || newValue === '') {

        return;

    }

    //Type appropriate comment here, and begin script below
    var x = g_form.getReference('caller_id').vip;

    //checking the caller is vip or not

    g_form.addInfoMessage(x);

    var z = g_form.getDisplayBox('caller_id').value;

    // print the caller name 

    g_form.addInfoMessage(z);

    if (x == true) {

        g_form.addInfoMessage("caller is VIP ");

    } else {

        g_form.addInfoMessage('not VIP caller');

    }

}
 
6. Create a catalog form with 2 variables (Group Name and Group Description).
  After submitting the catalog request, approval will trigger and if any one of the approver approved then requested group will create automatically.
 

1.Create a maintain item > two variable > create workflow .

2.Run script :- 

 

var gr = new GlideRecord('sys_user_group');

 gr.initialize();

 gr.name = current.variables.group_name;

 gr.description = current.variables.group_description;

 gr.insert();
 
7. Update the records of resolved state incidents to closed state how can do this?
    Background Script
 
 var gr = new GlideRecord('incident');

 gr.addEncodedQuery('state=6');

 gr.query();

 while(gr.next()){

 gr.state= '7'

 gr.update();

 }

 gs.addInfoMessage(gr.getRowCount());


 
 
8. If user has admin role then he do the change on the list view & non admin user cannot  do the changes in list view , How to approach this scenarios ?
 > with the help of list control we restrict these things.
 
9. Fetch the Priority 1 then update those records with priority 2.    
var gr = new GlideRecord('incident');

gr.addQuery('priority=1');

gr.query();

while(gr.next()){

gr.impact= '1';

gr.urgency = '2';

gr.update();

}

gs.addInfoMessage(gr.getRowCount());
 
 
10. Fetch the records which manager is ( abel tutor ).
Method1 :- 
 
  var gr = new GlideRecord('sys_user');

// pass the query

gr.addEncodedQuery('manager=a539818997022110f22d3766f053af50');

gr.query();

while(gr.next()){

gs.addInfoMessage(gr.user_name);

}
Method2 :- 
 
var gr = new GlideRecord('sys_user');

// passing the sys_id of the manager

gr.addQuery('manager' , 'a539818997022110f22d3766f053af50');

gr.query();

while(gr.next()){

gs.addInfoMessage(gr.user_name);

}
11. Find out the records which category is network?
 
 
var gr = new GlideRecord('incident');

gr.addQuery('category' , 'network');

gr.query();

while(gr.next()){

gs.addInfoMessage("Total number  = " +gr.number); 

}

gs.addInfoMessage(gr.getRowCount());
 
 
12. Find out the last created 5 records in the incident table.
 
 
var gr = new GlideRecord('incident');

gr.setLimit(5);

gr.orderByDesc('sys_created_on');

gr.query();

while(gr.next()){

gs.addInfoMessage(gr.number);

}
13. Find out the incident number which assigned to value is specific sys_id value?
 
var gr = new GlideRecord('incident');

gr.addEncodedQuery('assigned_to=c84f6cea97352110f22d3766f053afcd');

// Passing the sys_id of the user

//gr.addQuery('assigned_to' , 'c84f6cea97352110f22d3766f053afcd');

gr.query();

while(gr.next()){

gs.addInfoMessage(gr.number);

}

gs.addInfoMessage(gr.getRowCount());
14. Find out the records according caller and critical priority (P1).
 
 
var incgr = new GlideAggregate('incident');

incgr.addAggregate('COUNT','caller_id');

incgr.query();

while(incgr.next())

{

    var caller = incgr.getDisplayValue('caller_id');

    var count = incgr.getAggregate('COUNT','caller_id');

    gs.print("Caller "+ caller + " : count - " + count);


    var incPrio1GR = new GlideRecord('incident');

    incPrio1GR.addQuery('caller_id', incgr.getValue('caller_id'));

    incPrio1GR.addQuery('priority', '1');

    incPrio1GR.query();

    while (incPrio1GR.next()){

        gs.info('Prio 1 INC : ' + incPrio1GR.getValue('number'));

    }

}




 
15. When parent incident is closed then closed the child incident .
solution :-  Business rule
> Table :- Incident
> When to run  :- After and click the update check box.
> Condition :- State changes to closed.
Advanced :- 
 
(function executeRule(current, previous /*null when async*/ ) {

    // Add your code here

    var grIncident = new GlideRecord('incident');

    grIncident.addQuery('parent_incident', current.sys_id);

    grIncident.query();

    while (grIncident.next()) {

        grIncident.close_code = current.close_code;

        grIncident.close_notes = current.close_notes;

        grIncident.state = 7;

        grIncident.update();

    }

})(current, previous);
 
0 REPLIES 0