File tree Expand file tree Collapse file tree 3 files changed +92
-0
lines changed
Client-Side Components/UI Actions/Close Related HR cases & HR tasks Expand file tree Collapse file tree 3 files changed +92
-0
lines changed Original file line number Diff line number Diff line change 1+ Scenario:-
2+
3+ Table: HR Case
4+
5+ Create a form button named "Check related item and Close Complete" feature and list down the related child HR cases and HR tasks
6+ in the pop-up message.
7+ Upon confirmation, it will close the current case and other listed items.
8+
9+ This will help in reducing the manual effort of closing items manually.
10+
11+ Scripts:
12+ Client UI script to handle the confirmation popup and state of current case.
13+
14+ GlideAJAX enabled script include to fetch the data and close the related items.
Original file line number Diff line number Diff line change 1+ var close_item = Class . create ( ) ;
2+ close_item . prototype = Object . extendsObject ( global . AbstractAjaxProcessor , {
3+ getRelatedItems : function ( ) {
4+ var caseId = this . getParameter ( 'sysparm_case_id' ) ;
5+ var results = [ ] ;
6+
7+ // Get child HR cases
8+ var childCases = new GlideRecord ( 'sn_hr_core_case' ) ;
9+ childCases . addQuery ( 'parent' , caseId ) ;
10+ childCases . query ( ) ;
11+ while ( childCases . next ( ) ) {
12+ results . push ( { type : 'HR Case' , number : childCases . getValue ( 'number' ) } ) ;
13+ }
14+
15+ // Get tasks
16+ var tasks = new GlideRecord ( 'sn_hr_core_task' ) ;
17+ tasks . addQuery ( 'hr_case' , caseId ) ;
18+ tasks . query ( ) ;
19+ while ( tasks . next ( ) ) {
20+ results . push ( { type : 'HR Task' , number : tasks . getValue ( 'number' ) } ) ;
21+ }
22+
23+ return JSON . stringify ( results ) ;
24+ } ,
25+ closeRelatedItems : function ( ) {
26+ var caseId = this . getParameter ( 'sysparm_case_id' ) ;
27+
28+ // Close child cases
29+ var childCases = new GlideRecord ( 'sn_hr_core_case' ) ;
30+ childCases . addQuery ( 'parent' , caseId ) ;
31+ childCases . query ( ) ;
32+ while ( childCases . next ( ) ) {
33+ childCases . setValue ( 'state' , '3' ) ;
34+ childCases . update ( ) ;
35+ }
36+
37+ // Close tasks
38+ var tasks = new GlideRecord ( 'sn_hr_core_task' ) ;
39+ tasks . addQuery ( 'hr_case' , caseId ) ;
40+ tasks . query ( ) ;
41+ while ( tasks . next ( ) ) {
42+ tasks . setValue ( 'state' , '3' ) ;
43+ tasks . update ( ) ;
44+ }
45+
46+ return "done" ;
47+
48+ } ,
49+ type : 'close_task'
50+ } ) ;
Original file line number Diff line number Diff line change 1+ // Demo- OnClick function to execute
2+ function demo ( ) {
3+ var ga = new GlideAjax ( 'sn_hr_core.close_items' ) ;
4+ ga . addParam ( 'sysparm_name' , 'getRelatedItems' ) ;
5+ ga . addParam ( 'sysparm_case_id' , g_form . getUniqueValue ( ) ) ;
6+ ga . getXMLAnswer ( function ( response ) {
7+ // If there exist related items
8+ var items = JSON . parse ( response ) ;
9+ if ( items . length > 0 ) {
10+ var msg = "This case has related items:\n" ;
11+ items . forEach ( function ( item ) {
12+ msg += "- " + item . type + ": " + item . number + "\n" ;
13+ } ) ;
14+ msg += "\nDo you want to close them as well?" ;
15+ if ( confirm ( msg ) ) {
16+ // close current HR case
17+ g_form . setValue ( 'state' , '3' ) ;
18+ g_form . save ( ) ;
19+ }
20+ } else {
21+ // If no related item is associated
22+ if ( confirm ( "No related items found. Close this case?" ) ) {
23+ g_form . setValue ( 'state' , '3' ) ;
24+ g_form . save ( ) ;
25+ }
26+ }
27+ } ) ;
28+ }
You can’t perform that action at this time.
0 commit comments