Genarate the barcode for the multiple asset

KumarAyush6265
Tera Contributor

I face some issue in barcode genration for the multiple asset selected from the  list view so please give me any workaround ?

1 ACCEPTED SOLUTION

Sanjay191
Tera Sage

Hello @KumarAyush6265   Please refer below code and let me if anyerror has occur

UI Page:-

<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
    <j:set var="jvar_alm_asset_id" value="${sysparm_alm_asset}" />
    <g:include_script src="jsbarcode.jsdbx" />

    <script>
        count=0;
    </script>

    <g:evaluate var="sysparm_ids">
        <!-- var sysparm_ids =
        
        var sysparm_ids = RP.getParameterValue("sysparm_id");
        sysparm_ids;
    </g:evaluate>

    <j:forEach var="sys_id" items="${sysparm_ids.split(',')}">
        <g:evaluate var="jvar_record" object="true" jelly="true">
            var gr = new GlideRecord("alm_hardware");
            gr.get("${sys_id}");
            gr;
        </g:evaluate>
        <g:evaluate var="jvar_asset_tag" object="true" jelly="true">
            var gr = new GlideRecord("alm_hardware");
            gr.get("${sys_id}");
            var value = gr.getDisplayValue('asset_tag').toString();
            value;
        </g:evaluate>
       

        <input type='hidden' name='assetTag' id="assetTag" value="${jvar_asset_tag}" />
        <style>
            td {
                font-size: 8px;
                text-align: center;
                vertical-align: top;
            }


            @media print {
                @page {
                    margin: 0;
                }
            }
        </style>


        <table style="width:100%; height:100%">
            <tr>
                <td colspan="2">
                    <!-- Create a valid svg element with width and height attributes -->
                    <svg id="barcode" width="200" height="50"></svg>
                </td>
            </tr>
            <tr>
                <td>Model: ${jvar_record.getDisplayValue('model')}</td>
                <td>Serial No: ${jvar_record.getDisplayValue('serial_number')}</td>
            </tr>
        </table>

        <script>
            //alert( '${jvar_record.getDisplayValue('asset_tag')}');
        var barcode ='${jvar_record.getDisplayValue('asset_tag')}';
       
var labelText = "Asset tag: " +  '${jvar_record.getDisplayValue('asset_tag')}'; //"  Host Name::"  +  gel("hostName").value;//serialNO  Asset
// Link to JsBarcode docs and options: http://lindell.me/JsBarcode/
var barbi = JsBarcode("#barcode", barcode, { format: "CODE39", width: 1, height: 30, margin: 1, textMargin: 1, textAlign: "left", fontSize: 8, text: labelText });
barbi._renderProperties[0].element.id = barbi._renderProperties[0].element.id + count ;
// console.log(barbi._renderProperties[0].element.id);
// console.log(count++);
        </script>
    </j:forEach>
</j:jelly>

UI Page -

 function printBarCodeLabel(){
  var dialog = new GlideDialogWindow('printBarCodeLabel');
    dialog.setTitle('Barcode');
    dialog.setPreference('sysparm_id',g_list.getChecked());
    dialog.render();

}

and please install the ui script jsBarcode as libarary to genrate the barcode 


View solution in original post

19 REPLIES 19

Mark Manders
Mega Patron

What is 'some issue'? What isn't working? What did you already try? I know it's Friday, but if you want help, you at least have to provide us the information needed to start on helping you.


Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark

Sanjay191
Tera Sage

Hello @KumarAyush6265   Please refer below code and let me if anyerror has occur

UI Page:-

<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
    <j:set var="jvar_alm_asset_id" value="${sysparm_alm_asset}" />
    <g:include_script src="jsbarcode.jsdbx" />

    <script>
        count=0;
    </script>

    <g:evaluate var="sysparm_ids">
        <!-- var sysparm_ids =
        
        var sysparm_ids = RP.getParameterValue("sysparm_id");
        sysparm_ids;
    </g:evaluate>

    <j:forEach var="sys_id" items="${sysparm_ids.split(',')}">
        <g:evaluate var="jvar_record" object="true" jelly="true">
            var gr = new GlideRecord("alm_hardware");
            gr.get("${sys_id}");
            gr;
        </g:evaluate>
        <g:evaluate var="jvar_asset_tag" object="true" jelly="true">
            var gr = new GlideRecord("alm_hardware");
            gr.get("${sys_id}");
            var value = gr.getDisplayValue('asset_tag').toString();
            value;
        </g:evaluate>
       

        <input type='hidden' name='assetTag' id="assetTag" value="${jvar_asset_tag}" />
        <style>
            td {
                font-size: 8px;
                text-align: center;
                vertical-align: top;
            }


            @media print {
                @page {
                    margin: 0;
                }
            }
        </style>


        <table style="width:100%; height:100%">
            <tr>
                <td colspan="2">
                    <!-- Create a valid svg element with width and height attributes -->
                    <svg id="barcode" width="200" height="50"></svg>
                </td>
            </tr>
            <tr>
                <td>Model: ${jvar_record.getDisplayValue('model')}</td>
                <td>Serial No: ${jvar_record.getDisplayValue('serial_number')}</td>
            </tr>
        </table>

        <script>
            //alert( '${jvar_record.getDisplayValue('asset_tag')}');
        var barcode ='${jvar_record.getDisplayValue('asset_tag')}';
       
var labelText = "Asset tag: " +  '${jvar_record.getDisplayValue('asset_tag')}'; //"  Host Name::"  +  gel("hostName").value;//serialNO  Asset
// Link to JsBarcode docs and options: http://lindell.me/JsBarcode/
var barbi = JsBarcode("#barcode", barcode, { format: "CODE39", width: 1, height: 30, margin: 1, textMargin: 1, textAlign: "left", fontSize: 8, text: labelText });
barbi._renderProperties[0].element.id = barbi._renderProperties[0].element.id + count ;
// console.log(barbi._renderProperties[0].element.id);
// console.log(count++);
        </script>
    </j:forEach>
</j:jelly>

UI Page -

 function printBarCodeLabel(){
  var dialog = new GlideDialogWindow('printBarCodeLabel');
    dialog.setTitle('Barcode');
    dialog.setPreference('sysparm_id',g_list.getChecked());
    dialog.render();

}

and please install the ui script jsBarcode as libarary to genrate the barcode 


Thank You @Sanjay191  For the help

ninadpatwardhan
Tera Contributor

Hey Sanjay, I did apply the solution you have provided and the BarCode is getting generated. But the issue I am facing is that Same barcode is getting generated for multiple records. 


in the image below you can see while model name and serial number is different, the barcode of P1000241 is getting displayed repeatedly. 

 

ninadpatwardhan_0-1723211797841.png

 

I have just used the code which you have provided in the solution so there are no changes in the code. Can you please take a look and help me with this?

 

Thanks.