How to make all fields readonly in Catalog task only after 3 months after setting the state to Closed Complete?

Ramel
Mega Guru

Hi All,

I have a requirement to make fields read only after 3 months of after setting the state to Closed Complete. We have an existing client script that does set the fields to read only once the state is Closed Complete but they wanted to change that they still want to have the ability to modify even if the State is already Closed Complete if it is still within 3 months when the state was changed to Closed Complete.

Anyone had any idea how to do this implementation following the best practice. My idea is to create a system property similar to auto incident closure then execute some script once 3 months is reached. Can someone help how to put things together to make it work?

Regards,

 

12 REPLIES 12

Hi @Ankur Bawiskar ,

There is already an existing onload client script that makes the fields read only once the state is closed complete. Can I just use the same client script and incorporate the system property to implement my requirement? Do you have some sample scripts how I can achieve the if condition before it execute the setting of fields to read only.

find_real_file.png

Thank you.

yes you can reuse the same.

Use the approach I shared.

Regards
Ankur

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

Hi @Ankur Bawiskar ,

Do you have sample script? Thanks.

logic I already shared 2 days ago

1) display Business rule: catalog task

-> check the difference between the closed time and now time

-> store flag in g_scratchpad if difference is more than 3

2) get the scratchpad flag in client script and make the fields readonly if flag is true

Regards
Ankur

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

Hi Ankur,

I created the system property below.

find_real_file.png

Then I created a script include below:

var Readonly = Class.create();
Readonly.prototype = Object.extendsObject(AbstractAjaxProcessor, {

checkIfRecordIsBeforePeriod: function() {
var periodInMonth = gs.getProperty('read_only');
var taskId = this.getParameter('sysparm_taskSysId');

var task = new GlideRecord('sc_task');
task.addEncodedQuery('state=3^ORstate=4^closed_atRELATIVELT@month@ago@3');
task.addQuery(periodInMonth, taskId);
task.query();
if(task.next()){
return true;
}
else{
return false;
}

}
});

 

Client script:

 

function onLoad() {

var periodInMonth = 0;
var ga = new GlideAjax('Readonly');
ga.addParam('sysparm_name', 'checkIfRecordIsBeforePeriod');
ga.addParam('sysparm_taskSysId', g_form.getUniqueValue());
ga.getXMLWait();
if (ga.getAnswer()) {
setReadOnlyRework();
}

 

function setReadOnlyRework() {
g_form.setReadOnly('request_item.u_test', true);

}

 

The test field that I created is still not editable even if it is still within the 3 months period. When the state is closed complete the  field become read only.

Can you advise what I miss in my scripts. 

Thanks.