How to make all fields readonly in Catalog task only after 3 months after setting the state to Closed Complete?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-07-2021 01:13 AM
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,
- Labels:
-
Instance Configuration
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-08-2021 07:31 PM
Hi
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.
Thank you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-08-2021 09:37 PM
yes you can reuse the same.
Use the approach I shared.
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-08-2021 09:43 PM
Hi
Do you have sample script? Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-08-2021 10:11 PM
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
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-19-2021 11:25 PM
Hi Ankur,
I created the system property below.
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.