making state of story read-only using UI Policy when attached scrum tasks are not completed.

vijayender_s
Tera Contributor

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.

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@vijayender_s 

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;

AnkurBawiskar_0-1744948544658.png

 

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.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

4 REPLIES 4

Shree_G
Kilo Sage

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.

Can you please share the reference script.

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);
	}
   }
}

 

 

Shree_G_1-1744950707661.png

 

 

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'
});

 

Shree_G_0-1744950683358.png

 


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.

Ankur Bawiskar
Tera Patron
Tera Patron

@vijayender_s 

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;

AnkurBawiskar_0-1744948544658.png

 

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.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader