From 83c390baf2f9f999eb4cd7d18cf4bb4521522795 Mon Sep 17 00:00:00 2001 From: chaitaliKundu Date: Sat, 18 Oct 2025 11:06:04 +0530 Subject: [PATCH 1/8] README.md --- .../PdfletterGeneration/README.md | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 Server-Side Components/Business Rules/PdfletterGeneration/README.md diff --git a/Server-Side Components/Business Rules/PdfletterGeneration/README.md b/Server-Side Components/Business Rules/PdfletterGeneration/README.md new file mode 100644 index 0000000000..6ba5d77aa5 --- /dev/null +++ b/Server-Side Components/Business Rules/PdfletterGeneration/README.md @@ -0,0 +1,22 @@ +#Contribution + +The Business Rule is triggered after an update on the sn_hr_core_case table, specifically when the case state is set to "Work in Progress". This rule generates a PDF letter based on the trigerred conditions. + +Document Template created seperately. Document Template Name - PDF Letter Employee.The Document Template Sys ID is passed within the script, and the corresponding document template has been created separately (refer to the attached screenshot for reference). +Document Template -> All Document Templates - > New +As per the script, the PDF letter is generated and named using the HR case subject's name — for example: +"Letter: " + empName + ".pdf". + +Functionality - +When a fulfiller changes the case state to "Work in Progress", the PDF letter is automatically generated and attached to the HR case record. + +Business Rule Description - + +Name - pdf Letter generation +Table - sn_hr_core_case +Condition - state is "work in Progress" +Update - Check the box +When -select after + + + From 5f52a2f0d15487806c8aabf942b338412cecef38 Mon Sep 17 00:00:00 2001 From: chaitaliKundu Date: Sat, 18 Oct 2025 11:11:08 +0530 Subject: [PATCH 2/8] pdfletter.js --- .../PdfletterGeneration/pdfletter.js | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 Server-Side Components/Business Rules/PdfletterGeneration/pdfletter.js diff --git a/Server-Side Components/Business Rules/PdfletterGeneration/pdfletter.js b/Server-Side Components/Business Rules/PdfletterGeneration/pdfletter.js new file mode 100644 index 0000000000..7b80a2ff3e --- /dev/null +++ b/Server-Side Components/Business Rules/PdfletterGeneration/pdfletter.js @@ -0,0 +1,32 @@ +(function executeRule(current, previous /*null when async*/ ) { + + // Add your code here + var recordId = current.sys_id.toString(); + var empName = current.subject_person; + + var templateId1 = gs.getProperty("sn_hr_core.letter"); // Document Template sysid + + + var pdfFileName1 = 'Letter:' +empName+ '.pdf'; //letter name + + + gs.info('[PDF Generation] HRC Number ' + recordId); + + try { + + var docGen1 = new sn_doc.GenerateDocumentAPI(); + docGen1.generateDocumentForTask(recordId, templateId1, pdfFileName1); + + gs.info('[PDF Generation] PDF attached to HRC: ' + recordId); + } + + + + catch (ex) { + gs.error('[PDF Generation] Failed: ' + ex.message); + } + current.setWorkflow(false); + + + +})(current, previous); From ce0dbee2eb4e335c02492d9c06820628ee6fdde9 Mon Sep 17 00:00:00 2001 From: chaitaliKundu Date: Sat, 18 Oct 2025 12:24:13 +0530 Subject: [PATCH 3/8] Delete Server-Side Components/Business Rules/PdfletterGeneration directory --- .../PdfletterGeneration/README.md | 22 ------------- .../PdfletterGeneration/pdfletter.js | 32 ------------------- 2 files changed, 54 deletions(-) delete mode 100644 Server-Side Components/Business Rules/PdfletterGeneration/README.md delete mode 100644 Server-Side Components/Business Rules/PdfletterGeneration/pdfletter.js diff --git a/Server-Side Components/Business Rules/PdfletterGeneration/README.md b/Server-Side Components/Business Rules/PdfletterGeneration/README.md deleted file mode 100644 index 6ba5d77aa5..0000000000 --- a/Server-Side Components/Business Rules/PdfletterGeneration/README.md +++ /dev/null @@ -1,22 +0,0 @@ -#Contribution - -The Business Rule is triggered after an update on the sn_hr_core_case table, specifically when the case state is set to "Work in Progress". This rule generates a PDF letter based on the trigerred conditions. - -Document Template created seperately. Document Template Name - PDF Letter Employee.The Document Template Sys ID is passed within the script, and the corresponding document template has been created separately (refer to the attached screenshot for reference). -Document Template -> All Document Templates - > New -As per the script, the PDF letter is generated and named using the HR case subject's name — for example: -"Letter: " + empName + ".pdf". - -Functionality - -When a fulfiller changes the case state to "Work in Progress", the PDF letter is automatically generated and attached to the HR case record. - -Business Rule Description - - -Name - pdf Letter generation -Table - sn_hr_core_case -Condition - state is "work in Progress" -Update - Check the box -When -select after - - - diff --git a/Server-Side Components/Business Rules/PdfletterGeneration/pdfletter.js b/Server-Side Components/Business Rules/PdfletterGeneration/pdfletter.js deleted file mode 100644 index 7b80a2ff3e..0000000000 --- a/Server-Side Components/Business Rules/PdfletterGeneration/pdfletter.js +++ /dev/null @@ -1,32 +0,0 @@ -(function executeRule(current, previous /*null when async*/ ) { - - // Add your code here - var recordId = current.sys_id.toString(); - var empName = current.subject_person; - - var templateId1 = gs.getProperty("sn_hr_core.letter"); // Document Template sysid - - - var pdfFileName1 = 'Letter:' +empName+ '.pdf'; //letter name - - - gs.info('[PDF Generation] HRC Number ' + recordId); - - try { - - var docGen1 = new sn_doc.GenerateDocumentAPI(); - docGen1.generateDocumentForTask(recordId, templateId1, pdfFileName1); - - gs.info('[PDF Generation] PDF attached to HRC: ' + recordId); - } - - - - catch (ex) { - gs.error('[PDF Generation] Failed: ' + ex.message); - } - current.setWorkflow(false); - - - -})(current, previous); From 637d6a5b9037fa8d722840d9c73e5257b8e4c3eb Mon Sep 17 00:00:00 2001 From: chaitaliKundu Date: Sat, 18 Oct 2025 23:45:36 +0530 Subject: [PATCH 4/8] README.md --- .../Fix scripts/Delete User Groups/README.md | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 Specialized Areas/Fix scripts/Delete User Groups/README.md diff --git a/Specialized Areas/Fix scripts/Delete User Groups/README.md b/Specialized Areas/Fix scripts/Delete User Groups/README.md new file mode 100644 index 0000000000..54094539d1 --- /dev/null +++ b/Specialized Areas/Fix scripts/Delete User Groups/README.md @@ -0,0 +1,33 @@ +# contribution + +A fix script is used to remove inactive users from the specified list of Groups. The script checks for users who have been inactive in the system more than 7 days from the current date and removes them from the respective groups accordingly. +If users are inactive within 7 days then users will skip for deletion. + +Additionally, if any of these users are assigned to existing open incidents, the "Assigned to" field on those open incidents will be cleared. + +Groups: +-------- + +IT ServiceNow L1 +IT ServiceNow L2 +IT ServiceNow L3 + + +Fix script Goal: +----------------- + +Fix script 1name - Remove Inactive Users from Groups +Record for Rollback - Enable check box + +The goal of Fix script is to clean up inactive users from the above mentioned groups in ServiceNow, and unassign anyincidents they were responsible for — but only if they have been inactive for more than 7 days. + + +Taking Groups sysid in system Property with "," seperator + +Queries group members (sys_user_grmember) where the group matches one of the specified groups. + +Skips for Active users , Inactive users who were updated in the last 7 days. + +Finds Incident assigned to the user that are not closed (assuming state = 3 means closed). Clears the assigned_to field and updates the record. + +System Property : creation for group sysid. From 00a5432b5433183ad858f385b7f997a572c67c3f Mon Sep 17 00:00:00 2001 From: chaitaliKundu Date: Sat, 18 Oct 2025 23:52:41 +0530 Subject: [PATCH 5/8] removeuser.js --- .../Delete User Groups/removeuser.js | 82 +++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 Specialized Areas/Fix scripts/Delete User Groups/removeuser.js diff --git a/Specialized Areas/Fix scripts/Delete User Groups/removeuser.js b/Specialized Areas/Fix scripts/Delete User Groups/removeuser.js new file mode 100644 index 0000000000..eb25b9e2b9 --- /dev/null +++ b/Specialized Areas/Fix scripts/Delete User Groups/removeuser.js @@ -0,0 +1,82 @@ +var SEVEN_DAYS_AGO = new GlideDateTime(); + +SEVEN_DAYS_AGO.addDaysUTC(-7); + +//Get group sys_ids from system property + +var groupSysIdsStr = gs.getProperty('inactiveuser.groupname'); + +if (!groupSysIdsStr) { + + + + +} + +var GroupSysIds = groupSysIdsStr.split(','); // Split grp sysid with , + +//group members in those groups + +var groupMemberGR = new GlideRecord('sys_user_grmember'); + +groupMemberGR.addQuery('group', 'IN', GroupSysIds.join(',')); + +groupMemberGR.query(); + +while (groupMemberGR.next()) { + + var userID = groupMemberGR.getValue('user'); + + if (!userID) continue; + + var userGR = new GlideRecord('sys_user'); + + if (!userGR.get(userID)) continue; + + if (userGR.active) continue; // Active user skip + + var updatedOn = new GlideDateTime(userGR.sys_updated_on); + + if (updatedOn.compareTo(SEVEN_DAYS_AGO) >= 0) { // User was updated within 7 days, so skip + + // gs.info("Skipping user: " + userGR.name + " - updated on " + userGR.getDisplayValue('sys_updated_on')); + + continue; + + } + + var groupName = groupMemberGR.group.getDisplayValue(); + + + + //Unassign Incident record + + var inc = new GlideRecord('incident'); + + inc.addQuery('assigned_to', userID); + + + inc.addQuery('state', '!=', '3'); + + inc.query(); + + while (inc.next()) { + + + inc.assigned_to = ''; + + inc.update(); + + + + } + + + + // Remove user from group + + gs.info("Removing user: " + userGR.name + " from group: " + groupName); + + groupMemberGR.deleteRecord(); + +} From 913b17e396f6be1b6d02dddb61d7ec0f24fb4212 Mon Sep 17 00:00:00 2001 From: chaitaliKundu Date: Sat, 18 Oct 2025 23:57:55 +0530 Subject: [PATCH 6/8] Delete Specialized Areas/Fix scripts/Delete User Groups directory --- .../Fix scripts/Delete User Groups/README.md | 33 -------- .../Delete User Groups/removeuser.js | 82 ------------------- 2 files changed, 115 deletions(-) delete mode 100644 Specialized Areas/Fix scripts/Delete User Groups/README.md delete mode 100644 Specialized Areas/Fix scripts/Delete User Groups/removeuser.js diff --git a/Specialized Areas/Fix scripts/Delete User Groups/README.md b/Specialized Areas/Fix scripts/Delete User Groups/README.md deleted file mode 100644 index 54094539d1..0000000000 --- a/Specialized Areas/Fix scripts/Delete User Groups/README.md +++ /dev/null @@ -1,33 +0,0 @@ -# contribution - -A fix script is used to remove inactive users from the specified list of Groups. The script checks for users who have been inactive in the system more than 7 days from the current date and removes them from the respective groups accordingly. -If users are inactive within 7 days then users will skip for deletion. - -Additionally, if any of these users are assigned to existing open incidents, the "Assigned to" field on those open incidents will be cleared. - -Groups: --------- - -IT ServiceNow L1 -IT ServiceNow L2 -IT ServiceNow L3 - - -Fix script Goal: ------------------ - -Fix script 1name - Remove Inactive Users from Groups -Record for Rollback - Enable check box - -The goal of Fix script is to clean up inactive users from the above mentioned groups in ServiceNow, and unassign anyincidents they were responsible for — but only if they have been inactive for more than 7 days. - - -Taking Groups sysid in system Property with "," seperator - -Queries group members (sys_user_grmember) where the group matches one of the specified groups. - -Skips for Active users , Inactive users who were updated in the last 7 days. - -Finds Incident assigned to the user that are not closed (assuming state = 3 means closed). Clears the assigned_to field and updates the record. - -System Property : creation for group sysid. diff --git a/Specialized Areas/Fix scripts/Delete User Groups/removeuser.js b/Specialized Areas/Fix scripts/Delete User Groups/removeuser.js deleted file mode 100644 index eb25b9e2b9..0000000000 --- a/Specialized Areas/Fix scripts/Delete User Groups/removeuser.js +++ /dev/null @@ -1,82 +0,0 @@ -var SEVEN_DAYS_AGO = new GlideDateTime(); - -SEVEN_DAYS_AGO.addDaysUTC(-7); - -//Get group sys_ids from system property - -var groupSysIdsStr = gs.getProperty('inactiveuser.groupname'); - -if (!groupSysIdsStr) { - - - - -} - -var GroupSysIds = groupSysIdsStr.split(','); // Split grp sysid with , - -//group members in those groups - -var groupMemberGR = new GlideRecord('sys_user_grmember'); - -groupMemberGR.addQuery('group', 'IN', GroupSysIds.join(',')); - -groupMemberGR.query(); - -while (groupMemberGR.next()) { - - var userID = groupMemberGR.getValue('user'); - - if (!userID) continue; - - var userGR = new GlideRecord('sys_user'); - - if (!userGR.get(userID)) continue; - - if (userGR.active) continue; // Active user skip - - var updatedOn = new GlideDateTime(userGR.sys_updated_on); - - if (updatedOn.compareTo(SEVEN_DAYS_AGO) >= 0) { // User was updated within 7 days, so skip - - // gs.info("Skipping user: " + userGR.name + " - updated on " + userGR.getDisplayValue('sys_updated_on')); - - continue; - - } - - var groupName = groupMemberGR.group.getDisplayValue(); - - - - //Unassign Incident record - - var inc = new GlideRecord('incident'); - - inc.addQuery('assigned_to', userID); - - - inc.addQuery('state', '!=', '3'); - - inc.query(); - - while (inc.next()) { - - - inc.assigned_to = ''; - - inc.update(); - - - - } - - - - // Remove user from group - - gs.info("Removing user: " + userGR.name + " from group: " + groupName); - - groupMemberGR.deleteRecord(); - -} From e05cdcfa175b3ef7af04bfd415232d5c8b28bde9 Mon Sep 17 00:00:00 2001 From: chaitaliKundu Date: Sun, 19 Oct 2025 00:01:16 +0530 Subject: [PATCH 7/8] README.md --- .../Fix scripts/Remove User Groups/README.md | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 Specialized Areas/Fix scripts/Remove User Groups/README.md diff --git a/Specialized Areas/Fix scripts/Remove User Groups/README.md b/Specialized Areas/Fix scripts/Remove User Groups/README.md new file mode 100644 index 0000000000..a5b9885ee0 --- /dev/null +++ b/Specialized Areas/Fix scripts/Remove User Groups/README.md @@ -0,0 +1,23 @@ +contribution +A fix script is used to remove inactive users from the specified list of Groups. The script checks for users who have been inactive in the system more than 7 days from the current date and removes them from the respective groups accordingly. If users are inactive within 7 days then users will skip for deletion. + +Additionally, if any of these users are assigned to existing open incidents, the "Assigned to" field on those open incidents will be cleared. + +Groups: +IT ServiceNow L1 IT ServiceNow L2 IT ServiceNow L3 + +Fix script Goal: +Fix script 1name - Remove Inactive Users from Groups Record for Rollback - Enable check box + +The goal of Fix script is to clean up inactive users from the above mentioned groups in ServiceNow, and unassign anyincidents they were responsible for — but only if they have been inactive for more than 7 days. + +Taking Groups sysid in system Property with "," seperator + +Queries group members (sys_user_grmember) where the group matches one of the specified groups. + +Skips for Active users , Inactive users who were updated in the last 7 days. + +Finds Incident assigned to the user that are not closed (assuming state = 3 means closed). Clears the assigned_to field and updates the record. + +System Property : Store groups sysid. + From 955c2b5407ba070c69fe5014aee5fad4a2d4effe Mon Sep 17 00:00:00 2001 From: chaitaliKundu Date: Sun, 19 Oct 2025 00:02:51 +0530 Subject: [PATCH 8/8] removeuser.js --- .../Remove User Groups/removeuser.js | 82 +++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 Specialized Areas/Fix scripts/Remove User Groups/removeuser.js diff --git a/Specialized Areas/Fix scripts/Remove User Groups/removeuser.js b/Specialized Areas/Fix scripts/Remove User Groups/removeuser.js new file mode 100644 index 0000000000..eb25b9e2b9 --- /dev/null +++ b/Specialized Areas/Fix scripts/Remove User Groups/removeuser.js @@ -0,0 +1,82 @@ +var SEVEN_DAYS_AGO = new GlideDateTime(); + +SEVEN_DAYS_AGO.addDaysUTC(-7); + +//Get group sys_ids from system property + +var groupSysIdsStr = gs.getProperty('inactiveuser.groupname'); + +if (!groupSysIdsStr) { + + + + +} + +var GroupSysIds = groupSysIdsStr.split(','); // Split grp sysid with , + +//group members in those groups + +var groupMemberGR = new GlideRecord('sys_user_grmember'); + +groupMemberGR.addQuery('group', 'IN', GroupSysIds.join(',')); + +groupMemberGR.query(); + +while (groupMemberGR.next()) { + + var userID = groupMemberGR.getValue('user'); + + if (!userID) continue; + + var userGR = new GlideRecord('sys_user'); + + if (!userGR.get(userID)) continue; + + if (userGR.active) continue; // Active user skip + + var updatedOn = new GlideDateTime(userGR.sys_updated_on); + + if (updatedOn.compareTo(SEVEN_DAYS_AGO) >= 0) { // User was updated within 7 days, so skip + + // gs.info("Skipping user: " + userGR.name + " - updated on " + userGR.getDisplayValue('sys_updated_on')); + + continue; + + } + + var groupName = groupMemberGR.group.getDisplayValue(); + + + + //Unassign Incident record + + var inc = new GlideRecord('incident'); + + inc.addQuery('assigned_to', userID); + + + inc.addQuery('state', '!=', '3'); + + inc.query(); + + while (inc.next()) { + + + inc.assigned_to = ''; + + inc.update(); + + + + } + + + + // Remove user from group + + gs.info("Removing user: " + userGR.name + " from group: " + groupName); + + groupMemberGR.deleteRecord(); + +}