Category: Scenario based QA - 2
Updated on: August 2, 2025  |  0

Scenario-Based Questions PART 2

๐ŸŽ“ Scenario-Based Question

Q1: You need to create a UI Action button that, when clicked, will automatically change the state of an incident to "Resolved" and also set the "Resolved by" field to the current user. How would you write the script for this UI Action?

Answer:

You can write the below script in a UI Action on the incident table.

  • ๐Ÿ“ Name: Resolve Incident
  • ๐Ÿ“‹ Table: Incident
  • ๐Ÿท๏ธ Action name: resolve_incident
  • ๐Ÿ”˜ Form button: โœ… Checked
  • ๐Ÿ–ฑ๏ธ OnClick: Leave blank (uses server-side script)
  • โš™๏ธ Condition: current.state != 6 (only show if not already resolved)

๐Ÿง  Server-side Script:

if (!gs.hasRole('itil')) {
  gs.addErrorMessage("You do not have permission to resolve incidents.");
  return;
}

current.state = 6; 
current.resolved_by = gs.getUserID();
current.resolved_at = new GlideDateTime();
current.update();
action.setRedirectURL(current);
  

โœ… Result: When clicked, the button resolves the incident, sets the current user as the resolver, and updates the resolution timestamp.

ย 

Q2: Write a script to print the list of incidents grouped by assignment group.

Answer:

Below is a script using GlideAggregate to group active incidents by assignment_group and display their count:

var gr = new GlideAggregate("incident");
gr.addQuery("active", true);
gr.addAggregate("COUNT");
gr.groupBy("assignment_group");
gr.query();

while (gr.next()) {
  var countOf = gr.getAggregate("COUNT");
  var groupName = gr.getDisplayValue("assignment_group");
  gs.print(countOf);
  gs.print(groupName);
}
  

๐Ÿง  Explanation:

  • ๐Ÿ”Ž Filters only active incidents.
  • ๐Ÿ“Š Groups results by assignment_group.
  • ๐Ÿงฎ Uses GlideAggregate for performance and count aggregation.
  • ๐Ÿ“ค Prints the count and name of each group to the log using gs.print().

Comments

No comments yet.


Log in to post a comment