dynamic creation of checkbox

SnowDEV2
Kilo Expert

Hi,

I want some value to be fetched from a table & display them as check-box in a catalog item.

Thanks in advance

27 REPLIES 27

Gurpreet07
Mega Sage

Hi Lathesh,



You could do this using a UI macro and script include. You need to call the function in the script include from that ui macro using GlideAjax. This macro could then be referenced from catalog variable of type macro.


Function in script include :


getCheckboxes: function(){


  var checkboxes = '' ;


  var grTable = new GlideRecord('table_name');


      grTable.query();


  while(grTable .next()){


  checkboxes += ','+grTable.fieldName ;


  }


  checkboxes = checkboxes.substring(1);


  return checkboxes ;


},




UI Macro :


<table id="container" style="width:100%;">


</table>


<script>


var checkArray = [] ;


  var gaChecks = new GlideAjax('Script_Include');


  gaChecks.addParam('sysparm_name','getCheckboxes');


  gaChecks.getXML(processResponse) ;


  function processResponse(response){


  var answer = response.responseXML.documentElement.getAttribute("answer");


checkArray =       answer.split(',');  


var htmlString =   '' ;


for(var i = 0; i&lt;checkArray.length;i++){


  var check = checkArray[i];


if((i+1)%4 == 1){                                           //this will provide 4 checks in a row


  htmlString +='<tr>';


  }


htmlString += '<td><input type="checkbox" class="iafCategories" value="'+check+'">'+check+'</input></td>';


}


if((i+1)%4 == 0){                                               //this will end row after 4 checks


  htmlString +='</tr>';


}


document.getElementById("container").innerHTML = htmlString ;


}


</script>


Hi gurpreet,



I have some problem in creating check-box in UI page. Check this link: Custom UI Page


Can I directly create check-box using any servicenow scripts. (Because unable to create check-box using HTML).


or


Can I directly get the check-box from form to UI page?



Any help would be appreciated.


Hi gurpreet,



I was testing this but doesnt work Ui macro doesnt display checkboxes, can you post a screenshot of how checkboxes are displayed ?


This is how it looks like



find_real_file.png


Thanks Gurpreet. Have you tested this in geneva ?