How i get image from a record in the table?

Alexandre17
Tera Expert

Hello. How i get image from a record in the table?
The problem is: get "current.image_field" to "delivery" to use in the business rule, to generate pdf, like this:

(function executeRule(current, previous /*null when async*/) {
	// Add your code here
	var html = current.html_template;
	var tablename = 'x_577462_limpdocsf_tb7_3';
	var targetTableSysId = current.getValue('sys_id');
	var print_pdf = current.getDisplayValue('emitir_pdf');
	var ano_numero_protocolo = current.getValue('ano_numero_protocolo') ;
	var imagem = current.getDisplayValue('imagem');	//here is the question!
	var data_atualizacao = current.sys_updated_on;
	var numero_nota = current.getDisplayValue('ano_numero_protocolo');
	var fileName = 'Nota n²' + numero_nota + data_atualizacao;
	var a = html.replace('x_ano_numero_protocolo', ano_numero_protocolo);
	var b = a.replace('x_emitir_pdf', print_pdf);
	var c = b.replace('x_imagem', imagem);//here goes to put image
	var v = new sn_pdfgeneratorutils.PDFGenerationAPI;
	var result = v.convertToPDF(c, tablename, targetTableSysId, fileName);
	current.update();
})(current, previous);

"var imagem = current.getDisplayValue('imagem');" not work. 

So, what is the other way? Exist something like current.getImage('field') ? 

 

 

Resolved, by other way.

Created field html, and get current, and after replace

var sys_id_imagem = current.imagem_html;
.
.
.
var c = b.replace('x_imagem', sys_id_imagem);
6 REPLIES 6

sachin_namjoshi
Kilo Patron
Kilo Patron

You will have to query sys_attachment table with attachment sys_id and then get the image.

Every images will be stored in sys_attachment table.

 

Regards,

Sachin

thanks,for your attention.

But, in table sys_attachment, "where" is the picture? This table is like a folder? 

Because in this table, we have columns Average image color, Chunk size bytes, Compressed, Content type etc.... dont have a column with the name/label/folder picture...

I think something like this:

var imagem = current.getValue('imagem');

var gr = new GlideRecord('sys_attachment');
    gr.addQuery('sys_id', imagem);
    gr.query();
    while (gr.next()) {
var tookpicture = gr.xxxxx;
}

so, what code i put in the xxxxx ?

thanks in advance

One more point: the image is in the same table....

find_real_file.png

Hitoshi Ozawa
Giga Sage
Giga Sage

Hi Alexandre,

.getValue() returns the sys_id of the image in the sys_attachment table. 

To add an image to be included in pdf,

var image = new sn_pdfgeneratorutils.Image(current.getValue());