how to make variables edited on sc_task's/ritm when request is open and after request is in closed state sc_task 's/ritm variables should be read-only.

Santhosh15
Tera Guru

Hello,

Could you please suggest, how to make the particular variables read-only, when all catalog task get closed.

If one catalog is open state and another catalog task is closed state, then the variable should be editable for both the task.

If both the catalog task are in closed state, then only the variable should be in read-only state in both the task.

I written below code in catalog client script on onload form applied to catalog task and Requested item.

But the request item variables are not making read-only, when ritm is close complete.

function onLoad() {

var ritm = g_form.getReference('request_item', callBackMethod);
alert("ritm");
}

function callBackMethod(ritm) {

if (ritm.state == '3' || ritm.state == '4' || ritm.state == '7') {
alert("testing");
g_form.setVariablesReadOnly(true);
}

}

Could you please help on this issue.

Thank you

 

@Ankur Bawiskar 

 

 

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@D Kumar Swamy 

try to update script as this to make it work for sc_req_item and sc_task

function onLoad() {

	if(g_form.getTableName() == 'sc_task')
		var ritm = g_form.getReference('request_item', callBackMethod);
	else{
		var state = g_form.getValue('state');		
		if (state == '3' || state == '4' || state == '7') {
			g_form.setVariablesReadOnly(true);
		}
	}
}

function callBackMethod(ritm) {
	if (ritm.state == '3' || ritm.state == '4' || ritm.state == '7') {
		alert("testing");
		g_form.setVariablesReadOnly(true);
	}
}

Regards
Ankur

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

View solution in original post

7 REPLIES 7

OlaN
Giga Sage
Giga Sage

Hi,

Whats the use case behind this requirement?

Why would you want users to change the variables on a task that's already closed?

It would be fairly simple to create a UI policy to set the variables to read-only if the state of the task itself is set to closed.
But if you need to check on other records (other tasks), you would need to do some GlideAjax and use a scriptinclude to check if the variables should be set to readonly or not.

Santhosh15
Tera Guru

Hello @OlaN 

We have a requirement when first catalog task is closed state and another catalog task is open state, then the variable should be editable for both the task.

Even one task is in open states, then variables should be editable.

Both tasks should be in closed state, Then only the variable is read-only state.

Can we have any sample example to creating Script include and Glide Ajax for making variable read-only when all task get closed.

Thanks

I understood your requirement.

What I was asking for is why.

Why do you want to allow users to edit variables on a task that is closed?

A good starter for learning GlideAjax can be found here.

Hello @OlaN 

I written below code to make the variables read-only when request item is close complete.

Written code on catalog client script onload function used.

Applied this code on Requested item and catalog task.

function onLoad() {

var ritm = g_form.getReference('request_item', callBackMethod);
alert("ritm");
}

function callBackMethod(ritm) {

if (ritm.state == '3' || ritm.state == '4' || ritm.state == '7') {
alert("testing");
g_form.setVariablesReadOnly(true);
}

}

 

But it is working for Catalog task and not working for Ritm, if you have any idea. please help on this.