UI Page checkbox

avinashdubey103
Tera Guru

I have a requirement to make the checkbox as checked when the u_internal field is 1 on UI Page :

avinashdubey103_0-1671022193325.png

I have written the following code :

<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">

<g:evaluate var ="jvar_text" expression ="RP.getWindowProperties().get('sysparm_sourceRecordId')"/>

<g:evaluate object ="true" jelly="true" >


var grTarget = new GlideRecord('sys_attachment');
grTarget.addQuery('table_sys_id',jelly.jvar_text);
grTarget.query();
</g:evaluate>
<input type='hidden' id='recSys' name ='recSys' value='${jvar_text}'></input>
<style>
table {
border-collapse: collapse;
width: 90%;
}

td{
width: 15% ;

}

th, td {
text-align: left;

width: 15% ;

padding: 6px;
}

tr:nth-child(even){background-color: #f2f2f2}

th {
background-color: #04AA6D;
color: white;
}
</style>
<table border="1" >

<tr>
<td><strong>File Name</strong> </td>
<td><strong>Content Type </strong></td>
<td><strong>Internal </strong> </td>
<td><strong id ="mycheck"> Display Attachment </strong></td>
</tr>
<g:for_each_record file="${grTarget}">
<tr>
<td>${grTarget.getValue("file_name")}</td>
<td>${grTarget.getValue("content_type")}</td>
<td>${grTarget.getValue("u_internal")}</td>
<td> <input style="margin-left: 20px;margin-left: 20px;margin-bottom: 5px;font-size: 16px;" class="targetAttachment" name="targetAttachment" id="${grTarget.sys_id}" title="sys_id_${grTarget.sys_id}"
value ='${grTarget.u_internal}==1?document.getElementById("mycheck").checked=true:document.getElementById("mycheck").checked=false' type="checkbox"></input>

</td>
</tr>
</g:for_each_record>
</table>

<input type="hidden" id="checkedattach" name="checkedattach" value=""/>
<input type="hidden" id="complete_request1" name="complete_request1" value=""/>
<br> </br>
<br> </br>

<g:dialog_buttons_ok_cancel ok_text="${gs.getMessage('Submit')}" ok_title="${gs.getMessage('Submit')}" ok="return makeattachmentvisible();" cancel_text="${gs.getMessage('Cancel')}" cancel_title="${gs.getMessage('Go back to record')}" cancel="return cancel();"/>


</j:jelly>

1 REPLY 1

Hafsa Asif
Tera Contributor

try adding the attribute of checked=true like this

<td> <input style="margin-left: 20px;margin-left: 20px;margin-bottom: 5px;font-size: 16px;" class="targetAttachment" name="targetAttachment" id="${grTarget.sys_id}" title="sys_id_${grTarget.sys_id}"
value ='${grTarget.u_internal}==1?document.getElementById("mycheck").checked=true:document.getElementById("mycheck").checked=false'

 

checked='${grTarget.u_internal}==1? true : false' type="checkbox"></input>
</td>