Need help with my onAfter transform script. It is not showing the image properly on the image prompt/field. Please help.

John Clyde Ap_a
Giga Expert

I am trying to dynamically add attachments to every imported record and want to automatically attach it to the image prompt, I tried a script but I cannot seem to make the image display properly work..

 

I have tried this script:

find_real_file.png

 

This is what it shows up:

find_real_file.png

Its not an image as there is no preview for it. I'm not sure why it is not showing the image.

find_real_file.png

I wanted to display the images just like the other image(note that I manually added the image, but I wanted to dynamically add it base on my script) in the pic below but its not showing it properly.

find_real_file.png

 

 

For reference this is my imported excel table.

find_real_file.png

Here is my mapped fields:

find_real_file.png

 

Can anyone please help? It's been a few days and I am still unfortunately stuck.

 

 

1 ACCEPTED SOLUTION

Hi,

This worked for me

Remove line 10 i.e. don't copy

Add these lines as you are removing line 10

Give correct name of image field from target table.

I assume you are loading images only into the target table from import set.

var attachmentRecord = new GlideRecord("sys_attachment");
attachmentRecord.orderByDesc("sys_created_on");
attachmentRecord.addQuery("table_name", target.sys_class_name);
attachmentRecord.addQuery("table_sys_id", target.sys_id);
attachmentRecord.addQuery("file_name", fileName);
attachmentRecord.query();
if(attachmentRecord.next()){

	var sysId = new global.VariableUtil().copyAttachment(attachmentRecord.getUniqueValue(), "ZZ_YY" + target.sys_class_name, target.sys_id);
	target.u_imageFieldName = sysId; // give your field name which holds image
	target.update();

}

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

24 REPLIES 24

Allen Andreas
Administrator
Administrator

Duplicate post: https://community.servicenow.com/community?id=community_question&sys_id=bf7527e41b11555056b699b8bd4b...


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

Hello Allen,

Sorry about that, I have deleted the other duplicated post.

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

It's an image type of field and not file attachment type field right?

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hello Ankur,

Yes, it is an image type of field

find_real_file.png

Is there a way I could make it work so that the attached file based from the script can be auto assigned to the image field? as I mainly want the attached image to be displayed automatically in the image field so it will show up like those other records in the table. 

find_real_file.png

find_real_file.png

 

Based from what I understood in the onAfter script, the green rectangle part of the script works as its mainly the attachment process as you have helped me before about it, but I am not sure as to why the red rectangle part of the script won't work. This was the thread I was basing it upon as you have suggested before. 

find_real_file.png