- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-17-2025 07:44 PM
Hi all.
I have a requirement where there will be scrum tasks attached to each story(rm_story). I want to restrict the user from changing the state of the story from work in progress( for eg, to complete or cancelled etc..) when the attached scrum tasks are not complete (state = complete).
I am trying to create a UI policy but am not understanding the script to use to dot-walk or capture the state of the scrum tasks.
Please advice.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-17-2025 08:57 PM
you can use field level WRITE ACL on state field and use advanced script
In advanced script check if all the scrum tasks are complete or not
There is already an OOTB Field level WRITE ACL, use script in it
https://instanceName.service-now.com/nav_to.do?uri=sys_security_acl.do?sys_id=2dbcab9fef601000a7450fa3f82256cc
var gr = new GlideRecord("rm_scrum_task");
gr.addEncodedQuery("story=" + current.sys_id + "^stateIN-6,1,2"); // any open scrum tasks
gr.setLimit(1);
gr.query();
if (gr.hasNext()) {
answer = false;
} else
answer = true;
OR
Another way is to use onChange + GlideAjax and stop user from updating and throw error
OR
Another way is to use before update business rule and stop the update
BR Condition: State Changes to Complete or State Changes to Cancelled
Script:
(function executeRule(current, previous /*null when async*/ ) {
// Add your code here
var gr = new GlideRecord("rm_scrum_task");
gr.addEncodedQuery("story=" + current.sys_id + "^stateIN-6,1,2"); // any open scrum tasks
gr.setLimit(1);
gr.query();
if (gr.hasNext()) {
gs.addErrorMessage('Story cannot be completed or cancelled as there are open scrum tasks');
current.setAbortAction(true);
}
})(current, previous);
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-17-2025 08:42 PM
Hello @vijayender_s ,
Use onLoad Client script with GlideAjax to achieve this.
If this solution helped resolve your issue, please consider marking it as helpful or correct.
This will assist others in finding the solution faster and close the thread.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-17-2025 08:47 PM
Can you please share the reference script.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-17-2025 09:32 PM
Sure @vijayender_s ,
Screenshots and code snippet below:
Client Script : OnLoad Table: "rm_story"
function onLoad() {
//Type appropriate comment here, and begin script below
var stroryId = g_form.getUniqueValue();
g_form.addInfoMessage('story Id ='+stroryId);
var ga = new GlideAjax('GetTaskNumber');
ga.addParam('sysparm_name','storyName');
ga.addParam('sysparm_stryId',stroryId);
ga.getXMLAnswer(StoryParse);
function StoryParse(response){
if(response == 'true'){
g_form.setReadOnly('state',true);
}
}
}
Script Include:
var GetTaskNumber = Class.create();
GetTaskNumber.prototype = Object.extendsObject(AbstractAjaxProcessor, {
storyName: function(){
var sId = this.getParameter("sysparm_stryId");
gs.log('SysId of story'+sId);
var grTask = new GlideRecord('rm_scrum_task');
grTask.addQuery('parent',sId);
grTask.addEncodedQuery('stateNOT IN3,4');
grTask.query();
if(grTask.next()){
var recExist = "true";
}
return recExist;
},
type: 'GetTaskNumber'
});
If this solution helped resolve your issue, please consider marking it as helpful or correct.
This will assist others in finding the solution faster and close the thread.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-17-2025 08:57 PM
you can use field level WRITE ACL on state field and use advanced script
In advanced script check if all the scrum tasks are complete or not
There is already an OOTB Field level WRITE ACL, use script in it
https://instanceName.service-now.com/nav_to.do?uri=sys_security_acl.do?sys_id=2dbcab9fef601000a7450fa3f82256cc
var gr = new GlideRecord("rm_scrum_task");
gr.addEncodedQuery("story=" + current.sys_id + "^stateIN-6,1,2"); // any open scrum tasks
gr.setLimit(1);
gr.query();
if (gr.hasNext()) {
answer = false;
} else
answer = true;
OR
Another way is to use onChange + GlideAjax and stop user from updating and throw error
OR
Another way is to use before update business rule and stop the update
BR Condition: State Changes to Complete or State Changes to Cancelled
Script:
(function executeRule(current, previous /*null when async*/ ) {
// Add your code here
var gr = new GlideRecord("rm_scrum_task");
gr.addEncodedQuery("story=" + current.sys_id + "^stateIN-6,1,2"); // any open scrum tasks
gr.setLimit(1);
gr.query();
if (gr.hasNext()) {
gs.addErrorMessage('Story cannot be completed or cancelled as there are open scrum tasks');
current.setAbortAction(true);
}
})(current, previous);
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader