how to get all the fields of custom table for PDF Generator.

sreevidya Kota
Giga Contributor

Dear All, 

I have requirement in PDF Generator for custom table. I am able to generate PDF for Custom table using UI action but I need to hard code the each and every field value to get inserted in PDF.  I need any other solution to get display the field values based on one  filed. When i have hard coded the values it is showing all the values whatever their in table. But i need to show few fields based on other field. Written code as below in UI action.

var v = new sn_pdfgeneratorutils.PDFGenerationAPI;

var boldltr1 = FinalString1.bold();

var field= 'Number: '+current.number + '<br>' + '<br>'+ 'Template Name: '+current.template_name +'<br>' + '<br>'+ 'Alt Hz: '+current.u_althz + '<br>'+ '<br>'+'CL Society: '+current.cl_society + '<br>'+ '<br>' +'Alt P (kWe): '+current.u_altpkwe ;

var recsysid = current.getUniqueValue();

var result = v.convertToPDF(field, "custom_table_name",recsysid, current.number);

Kindly provide your helpful inputs.

1 ACCEPTED SOLUTION

Hi SreeVidya,

please refer below code

var v = new sn_pdfgeneratorutils.PDFGenerationAPI();

var tableName = current.getTableName();
var columLabels = ['number']; //As number field is derived from extended table

var grDict = new GlideRecord('sys_dictionary');
grDict.addEncodedQuery('name=' + tableName + '^internal_type!=collection^internal_typeISNOTEMPTY');
grDict.query();

while(grDict.next()) {
  columLabels.push(grDict.element + '');
}

var fields = '';
for (f in columLabels) {
    if (!columLabels[f].startsWith('sys_')) { //to avoid sys fields
        if (fields.length > 0) //if value exists in fields
            fields += '<br><br>';

        fields += current[columLabels[f]].getLabel() + ' : ' + current[columLabels[f]].toString();
    }
}

var result = v.convertToPDF(fields, tableName, current.getUniqueValue(), current.number);

action.setRedirect(current);

View solution in original post

5 REPLIES 5

SumanthDosapati
Mega Sage
Mega Sage

Hi,

In the script, first you validate and get the fields what are needed and then pass only those fields to the function.

Example:

if(some condition)

{

var final_fields = abc,def
}

else if(some condition)

{

var final_fields = def,xyz
}

 

Now use final_fields in your pdf function.

 

Mark as correct and helpful if it solved your query.

Regards,

Sumanth

Sri Ram3
Tera Expert

Hi,

  You can try below code:

var v = new sn_pdfgeneratorutils.PDFGenerationAPI();

var fields = '';
for (f in current) {
    if (!f.startsWith('sys_')) { //to avoid sys fields
        if (fields.length > 0) //if value exists in fields
            fields += '<br><br>';

        fields += current[f].getLabel() + ' : ' + current[f].toString();
    }
}

var result = v.convertToPDF(fields, "custom_table_name",current.getUniqueValue(), current.number); 

action.setRedirect(current);

Hello Sri Ram, 

 

Thanks for your response. Tried the above code and getting all the fields which are their in extended table also. But only need this particular table data(not extended table).

 

Thanks in advance

Hi SreeVidya,

please refer below code

var v = new sn_pdfgeneratorutils.PDFGenerationAPI();

var tableName = current.getTableName();
var columLabels = ['number']; //As number field is derived from extended table

var grDict = new GlideRecord('sys_dictionary');
grDict.addEncodedQuery('name=' + tableName + '^internal_type!=collection^internal_typeISNOTEMPTY');
grDict.query();

while(grDict.next()) {
  columLabels.push(grDict.element + '');
}

var fields = '';
for (f in columLabels) {
    if (!columLabels[f].startsWith('sys_')) { //to avoid sys fields
        if (fields.length > 0) //if value exists in fields
            fields += '<br><br>';

        fields += current[columLabels[f]].getLabel() + ' : ' + current[columLabels[f]].toString();
    }
}

var result = v.convertToPDF(fields, tableName, current.getUniqueValue(), current.number);

action.setRedirect(current);