Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

How show the page number in the footer ?

Alexandre17
Tera Expert

Hello. How i show the pagenumber in the footer (in the Business rule to do a pdf) ? 

The code:

(function executeRule(current, previous /*null when async*/ ) {
    var html = current.html_template_resumo_adm;
    var tablename = ('x_bdb_5wa_00000447_solicitacoes');
    var targetTableSysId = current.getValue('sys_id');
    var funci = current.funci_beneficiario.name;
	var prefixo = current.prefixo_beneficiario.name;

    var fileName = 'Solicitação ' + (current.getDisplayValue('number')) + " " + (current.sys_updated_on);
    var a = html.replace('x_funci', funci);
	var b = a.replace('x_prefixo', prefixo);    

    var pageProperties = {
        PageSize: 'A4',
        GeneratePageNumber: 'true',
        TopOrBottomMargin: '72',        
        LeftOrRightMargin: '36'
    };
	
    var v = new sn_pdfgeneratorutils.PDFGenerationAPI().convertToPDFWithHeaderFooter(b, tablename, targetTableSysId, fileName, pageProperties);
    current.update();
})(current, previous);

The pdf:

find_real_file.png

2 REPLIES 2

Aman Kumar S
Kilo Patron

You need to update page rule, please follow below article to achieve the same(look for @page rule)

:

Generating Custom PDFs - using the new PDFGenerationAPI

 

Feel free to mark correct, If I answered your query.

Will be helpful for future visitors looking for similar questions 🙂

 

Best Regards
Aman Kumar

@Aman Kumar , ok, but where i put the code (below) ? "inside" the business rule, like this ?

 

(function executeRule(current, previous /*null when async*/ ) {
    var html = current.html_template_resumo_adm;
    var tablename = ('x_bdb_5wa_00000447_solicitacoes');
    var targetTableSysId = current.getValue('sys_id');
    var funci = current.funci_beneficiario.name;
	var prefixo = current.prefixo_beneficiario.name;

    var fileName = 'Solicitação ' + (current.getDisplayValue('number')) + " " + (current.sys_updated_on);
    var a = html.replace('x_funci', funci);
	var b = a.replace('x_prefixo', prefixo);    

    var pageProperties = {
        PageSize: 'A4',
        GeneratePageNumber: 'true',
        TopOrBottomMargin: '72',        
        LeftOrRightMargin: '36'
    };


<style>
   @page {
      size: A4 landscape;
      margin-left: 1cm;
      margin-top: 3cm;
      margin-right: 1cm;
      margin-bottom: 3cm;

      @bottom-right {
        font-family: sans-serif;
        font-weight: bold;
        font-size: 1em;
        content: counter(page);
      }
   }
</style>

	
    var v = new sn_pdfgeneratorutils.PDFGenerationAPI().convertToPDFWithHeaderFooter(b, tablename, targetTableSysId, fileName, pageProperties);
    current.update();
})(current, previous);