How to get the all selected checkbox values from HTML to Javascript
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-07-2022 02:58 AM
Hi community
I'm stuck on one requirement where I need to customize the Copy attachment
when the user click on the copy attachment, An UI page is open and there I need to fetch all the attachments sys_id which is present in the record and then user selects the attachment by the checkbox shown in below , but I'm unable to get the sys_id of both the attachment. and then it will pass to the Employee Document
UI page
UI Page XML HTML script
Im not much good in HTML
but I try
<?xml version="1.0" encoding="utf-8" ?>
<html>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
<j:set var="jvar_var_sysId" value="${sysparm_record_id}"/>
<j:set var="jvar_var_name" value="${sysparm_record_table}"/>
<g:evaluate var="jvar_now_GR" object="true">
var now_GR = new GlideRecord("sys_attachment");
now_GR.addEncodedQuery('table_name=${jvar_var_name}^table_sys_id=${jvar_var_sysId}');
now_GR.query();
now_GR;
</g:evaluate>
<g:ui_form>
<table>
<body>
<p>
<j:while test="${jvar_now_GR.next()}">
<style>
input.larger {
width: 15px;
height: 13px;
}
</style>
<label class="checkbox-inline">
<input type="checkbox" id="myCheck1" name="pl" value="${jvar_now_GR.getValue('sys_id')}">${jvar_now_GR.getValue('file_name')}</input>
<script>
var markedCheckbox = document.getElementsByName('pl');
var text = "";
for (var checkbox of markedCheckbox) {
if (checkbox.checked)
document.getElementById("myCheck1").innerHTML = text;
console.log("this is the sys_id "+text);
}
</script>
</label>
<br></br>
</j:while>
</p>
<tr>
<td>
<button class="btn btn-default" onclick="closeWindow()" style="margin-right:10px;">Cancel</button>
<button class="btn btn-primary" onclick="update_ticket()">Copy Selected</button>
</td>
</tr>
</body>
</table>
</g:ui_form>
</j:jelly>
</html>
UI page client script
function update_ticket(){
// alert(" inside the Copy att");
// var yes = document.getElementById("myCheck1").value;
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
// document.getElementById('update_ticket()').onclick = function() {
// var markedCheckbox = document.querySelectorAll('input[type="checkbox"]:checked');
// for (var checkbox of markedCheckbox) {
// document.body.append(checkbox.value + ' ');
// }
// }
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
var attach = gel('myCheck1').value;
alert("selected attachment is "+yes);
alert("selected attachment is IN GEL "+attach);
GlideDialogWindow().get().destroy();
}
function closeWindow(){
alert('cancle the copy operation');
GlideDialogWindow.get().destroy();
}
Thanks in advance
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-07-2022 05:14 AM
so you want to show files attached to current record and then what?
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-07-2022 10:52 AM - edited 12-07-2022 11:08 AM
then all selected attachment is copied into the employee document table.
if you have any suggestions for me then please let me know
regards
kunal