Mark Roethof
Tera Patron
Tera Patron

Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

 

Hi there,

 

Working with the out-of-the-box Checklist formatter? A nice feature. Though did you also encounter that when the record is closed (active=false) or a user does not have write access to that record, the Checklist items actually are still editable (not read-only)? There's an easy fix for this.

Checklist formatter

As mentioned, the Checklist formatter is out-of-the-box available. You could for example add the Checklist formatter to the Incident form.

 

find_real_file.png

 

find_real_file.png


Closed record, Checklist items still editable

All looks well and functions nicely. Though when displaying a closed record (active=false) or a record on which the logged-in user doesn't have write access to, still the Checklist items are editable (not read-only).


Updating out-of-the-box components

The Checklist (and with this the Checklist items) is shown when the Checklist formatter is available on a form. Looking at the Checklist formatter, this actually references a UI Macro: inline_checklist_macro.

 

find_real_file.png

 

Looking at the code of UI Macro inline_checklist_macro, on line 30 we would need to influence the read-only property. Out-of-the-box, this is hardcoded set to false. Ideally, we would influence this property so it is dynamically true or false. For example depending on the active flag or write access.

 

Within g2:evaluate, we could define a property dynamically and use this for the read-only property. For example:

 

var readonlyBool = false;
if(!current.canWrite()) {
	readonlyBool = true;
}

 

readonlyBool would now represent if the logged-in user has write access on the current record. Within g:macro_invoke we could use this readonlyBool on the read-only property by changing the read-only property to readonly="$[readonlyBool]".

 

You might also want to consider not using !current.canWrite, though current.active == false instead or a combination. That's completely up to you.

Full code UI Macro inline_checklist_macro

<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
	<g2:evaluate>
		var isBrowserSupported = (GlideVTBCompatibility.getCompatibility() != 'block');
		var isNewUI = gs.getProperty('glide.ui.doctype', 'false') == 'true';
		var isNewRecord = true;
		if (isBrowserSupported $[AMP]$[AMP] isNewUI) {
			var sysID = current.getUniqueValue();
			var tableName = current.getTableName();
			isNewRecord = current.isNewRecord();
		
			// get the checklist ID for this record
			var checklistID = null;
			var checklist = new GlideRecord("checklist");
			checklist.addQuery("document", sysID);
			checklist.addQuery("table", tableName);
			checklist.query();
			if (checklist.next())
				checklistID = checklist.getUniqueValue();
		}
		
		var readonlyBool = false;
		if(!current.canWrite()) {
			readonlyBool = true;
		}
	</g2:evaluate>
	<body>
		<j2:if test="$[!isNewRecord]">
			<g:macro_invoke macro="checklist_template" readonly="$[readonlyBool]" record="$[sysID]" 
							table="$[tableName]" checklistid="$[checklistID]"/>
		</j2:if>
	</body>
</j:jelly>

 

Result

When opening an Incident with a user that doesn't have write access on that Incident (Incident is closed, User has itil role), the Checklist items are now read-only.

 

find_real_file.png


Share

An Update Set with this updated UI Macro can be downloaded from Share:
- Checklist items still editable while record is closed [Fix]

---


And that's it actually. Hope you like it. If any questions or remarks, let me know!

 

C

If this content helped you, I would appreciate it if you hit bookmark or mark it as helpful.

 

Interested in more Articles, Blogs, Videos, Podcasts, Share projects I shared/participated in?
- Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

 

Kind regards,


Mark Roethof

ServiceNow Technical Consultant @ Quint Technology
1x ServiceNow Developer MVP

1x ServiceNow Community MVP

---

LinkedIn

Comments
REDDYBATTULS
Tera Contributor

Hi @Mark Roethof 

same changes i have done its working fine on HR case form level . in agent work space its not working. 

any suggestion for agent work space level for making checklist readonly once case is closed 

Version history
Last update:
‎08-18-2024 06:17 AM
Updated by:
Contributors