Make a Checklist readonly/mandatory

sspati
Kilo Contributor

I have created a checklist on form. Now I want to add certain rules on it like to make it visible/read-only or mandatory based on conditions.

As it is not a field of the table, I am unable to use UI policy of any kind of script for fields.

Could anyone please hep me on this.

6 REPLIES 6

harishdasari
Tera Guru

Hi Sudipta,



what ever fields you create it should be saved in table, can you go to Configure Dictionary of that field and see on which table it has been stored.



on which form(incident,problem, change etc) you have created the field ?



post a screenshot if possible.



Thank you


Hello Harish,



Here is the screenshot.


Its not created as a field in the form, hence configure dictionary is not shown. Its created from checklist formater in Configure Design.



checklist.png


This you can achieve using script include and BR something like below



Script Include:



var Test = Class.create();


Test.prototype = {


initialize: function() {


},




isChecked: function(id){


var gr = new GlideRecord("checklist");


gr.addQuery("document", id);


gr.query();


while (gr.next()) {


var gr_checkListItem = new GlideRecord("checklist_item");


gr_checkListItem.addQuery("checklist", gr.sys_id);


gr_checkListItem.addQuery("complete", false);


gr_checkListItem.query();


if (gr_checkListItem.next())


return false;


else


return true;


}


},




type: 'Test'


};





BR:


(function executeRule(current, previous /*null when async*/) {




var res=new Test().isChecked(current.sys_id);


if(res)


gs.addInfoMessage("Checklist is reviewed.");


else


gs.addErrorMessage("Please review the checklist.");




})(current, previous);


francescodotti
Mega Expert

Hi,


after trying with ACL and Client scripts, I found a very simple way.


You have to modify the UI Macro inline_checklist_macro. I added a condition linked to the state of the containing task



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();


if (current.state == -5 || current.state == 3 ) { // Pending or Closed


var readOnly = "true";


} else {


var readOnly = "false";


}


}


</g2:evaluate>


<body>


<j2:if test="$[!isNewRecord]">


<g:macro_invoke macro="checklist_template" readonly="$[readOnly]" record="$[sysID]"


table="$[tableName]" checklistid="$[checklistID]"/>


</j2:if>


</body>


</j:jelly>





Thanks.


PS: Hit like, Helpful, Correct, if it answers your question.