Created
February 2, 2024 22:28
-
-
Save asimpkin/40613887eb22081f45cc97bea9075dac to your computer and use it in GitHub Desktop.
ServiceNow - Business Rule - rm_story - update epics percent complete
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<unload unload_date="2024-02-02 19:57:18"> | |
<sys_script action="INSERT_OR_UPDATE"> | |
<abort_action>false</abort_action> | |
<access>package_private</access> | |
<action_delete>false</action_delete> | |
<action_insert>true</action_insert> | |
<action_query>false</action_query> | |
<action_update>true</action_update> | |
<active>true</active> | |
<add_message>false</add_message> | |
<advanced>true</advanced> | |
<change_fields>false</change_fields> | |
<client_callable>false</client_callable> | |
<collection>rm_story</collection> | |
<condition>!current.epic.nil() && ((typeof origSysId === 'undefined') || origSysId == null || (origSysId == current.sys_id)) </condition> | |
<description/> | |
<execute_function>false</execute_function> | |
<filter_condition table="rm_story"/> | |
<is_rest>false</is_rest> | |
<message/> | |
<name>Update epics percent complete </name> | |
<order>500</order> | |
<priority>100</priority> | |
<rest_method display_value=""/> | |
<rest_method_text/> | |
<rest_service display_value=""/> | |
<rest_service_text/> | |
<rest_variables/> | |
<role_conditions/> | |
<script><![CDATA[/* | |
2024-02-02 - AJ Simpkin - asimpkin@kpmg.ca | |
Update the parent epic percent complete when the story updates. | |
*/ | |
if( !current.getTableName().startsWith("tm_") ) { | |
updateParentsPercent(); | |
} | |
function updateParentsPercent() { | |
//Calculate durations from sibling tasks | |
var totalDur = 0; | |
var workedDuration = 0; | |
var percentCalc = 0; | |
var sibling = new GlideRecord('rm_story'); | |
sibling.addQuery('epic', current.epic); | |
sibling.query(); | |
while(sibling.next()){ | |
totalDur += sibling.duration.getGlideObject().getNumericValue(); | |
if(sibling.percent_complete){ | |
workedDuration += sibling.duration.getGlideObject().getNumericValue() * (sibling.percent_complete / 100); | |
//gs.addInfoMessage(sibling.number); // error logging to screen | |
} | |
} | |
//Now update the parents percent (if needed) | |
percentCalc = (workedDuration / totalDur) * 100; | |
if (!isNaN(percentCalc)) { | |
var parent = new GlideRecord('rm_epic'); | |
if (parent.get(current.epic.sys_id)) // AJ Simpkin - 2024-02-02 | |
if(parent.percent_complete != percentCalc) { | |
parent.percent_complete = percentCalc; | |
parent.update(); | |
} | |
} | |
}]]></script> | |
<sys_class_name>sys_script</sys_class_name> | |
<sys_created_by>asimpkin@kpmg.ca</sys_created_by> | |
<sys_created_on>2024-02-02 19:34:04</sys_created_on> | |
<sys_domain>global</sys_domain> | |
<sys_domain_path>/</sys_domain_path> | |
<sys_id>5b2c9cf21b004e100f8d20252a4bcb4d</sys_id> | |
<sys_mod_count>6</sys_mod_count> | |
<sys_name>Update epics percent complete </sys_name> | |
<sys_overrides display_value=""/> | |
<sys_package display_value="Global" source="global">global</sys_package> | |
<sys_policy/> | |
<sys_scope display_value="Global">global</sys_scope> | |
<sys_update_name>sys_script_5b2c9cf21b004e100f8d20252a4bcb4d</sys_update_name> | |
<sys_updated_by>asimpkin@kpmg.ca</sys_updated_by> | |
<sys_updated_on>2024-02-02 19:57:03</sys_updated_on> | |
<template/> | |
<when>after</when> | |
</sys_script> | |
</unload> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Import this .XML file into ServiceNow to enable the update of an Agile STRY to calculate and update the parent EPIC with the percentage of all sibling records.