How to get the all selected checkbox values from HTML to Javascript

Kunal Waghmare1
Tera Contributor

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 Screenshot (84).pngScreenshot (85).png


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

 
@Ankur Bawiskar

@Chuck Tomasi 

 

@Saurav11 

@Gunjan Kiratkar 

@Mark Roethof 

@Brad Bowman  

 

 

2 REPLIES 2

Ankur Bawiskar
Tera Patron
Tera Patron

@Kunal Waghmare1 

so you want to show files attached to current record and then what?

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

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