logo

NJP

Checklist items still editable while record is closed

Import · Aug 31, 2020 · article

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.

image

image

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.

image

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.

image

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!

Kind regards,

Mark Roethof

ServiceNow Technical Consultant @ Quint Technology

1x ServiceNow Developer MVP

1x ServiceNow Community MVP

---

LinkedIn

image

View original source

https://www.servicenow.com/community/developer-articles/checklist-items-still-editable-while-record-is-closed/ta-p/2321346