Disable ZZ_YY prefix from attachment when added through record producer

Chenab Khanna
Tera Expert

Hi,

I have a 'attachment' type variable in my record producer which i have made mandatory. When the user uploads any attachment, i want the attachment to get saved in the record created. But instead, it is hiding it.

I can see the entry created in sys_attachment but under table name field, a prefix ZZ_YY is getting added which is making the attachment hidden.

Please find the field below - 

find_real_file.png

 

Record in sys_attachment - 

find_real_file.png

Can anyone help me get this attachment added in the record as it happens when add any attachment from here - 

find_real_file.png

1 ACCEPTED SOLUTION

@Chenab Khanna 

This worked well for me

1) I created Async After Insert BR on the target table

2) Script as this

a) Remove the ZZ_YY

b) Then use the Copy Attachment

(function executeRule(current, previous /*null when async*/) {

	// Add your code here
	var gr = new GlideRecord("sys_attachment");
	gr.addQuery("table_name", "ZZ_YY" + current.getTableName());
	gr.addQuery("table_sys_id", current.sys_id);
	gr.query();
	if (gr.next()) {
		gr.table_name = current.getTableName();
		gr.update();
		new global.VariableUtil().copy(gr.sys_id, current.getTableName(), current.sys_id); 
	}

})(current, previous);

Output:

1) The file added to the record

find_real_file.png

2) The file present on the attachment variable

find_real_file.png

Regards
Ankur

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

View solution in original post

56 REPLIES 56

@Chenab Khanna 

Glad that it worked.

Would you mind marking my response as correct and helpful if I was able to help in your original question.

Regards
Ankur

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

Hi,

Seems that table is custom table

you missed the initialize()

var attachment = new GlideRecord('sys_attachment');
attachment.addQuery('table_name',current.getTableName());
attachment.addQuery('table_sys_id',current.sys_id);
attachment.query();
if(attachment.next()){
gs.info("code working right ");
var gr = new GlideRecord('x_eyit2_bo_journal_entry_data_mapping');

gr.initialize();
gr.u_journal_header = current.sys_id;
gr.setValue('u_status','ready');

var newRecord = gr.insert();
new global.VariableUtil().copy(attachment.sys_id, gr.getTableName(),newRecord);
}

Regards
Ankur

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

Hi Ankur,

I am not able to get the info message 'code working right' in logs.

Record is not getting created in the table.

Hi,

I could see the table is in some custom scope

So is the create operation allowed on the table "x_eyit2_bo_journal_entry_data_mapping" from all scope?

Is the BR also in same scope

Regards
Ankur

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

Yes all are in same scope.

Only the BR written to remove ZZ_YY is written in global as the sys_attachment table had to be updated.