How to add attachment variable on header on the request form instead of updating in work notes

Are Kaveri
Tera Contributor

Hi ,

 

I have below requirement. 
one of our clients asked to add a variable on my record producer form.

if end user attaches any attachment and submit the request. It is updating in worknotes or activity log but not on the header.

my requirement is whenever end users add any attachment he should be able to see on the request form header itself .

 

can someone help me how to add it on header of the request form instead of adding in activity log.

1 ACCEPTED SOLUTION

@Are Kaveri 

you didn't mention that in your question.

For that you need to use while loop in script

(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();
	while (gr.next()) {
		gr.table_name = current.getTableName();
		gr.update();
		new global.VariableUtil().copyAttachment(gr.sys_id, current.getTableName(), current.sys_id); 
	}

})(current, previous);

If my response helped please mark it correct and close the thread so that it benefits future readers.

 

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

View solution in original post

8 REPLIES 8

@Are Kaveri 

you didn't mention that in your question.

For that you need to use while loop in script

(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();
	while (gr.next()) {
		gr.table_name = current.getTableName();
		gr.update();
		new global.VariableUtil().copyAttachment(gr.sys_id, current.getTableName(), current.sys_id); 
	}

})(current, previous);

If my response helped please mark it correct and close the thread so that it benefits future readers.

 

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

Hi Ankur,

 

Thank you for the script, I have found it very helpful.

The only issue I have is that the attachment is appearing twice on the request.

Do you know why this would be happening?

 

Feasood_0-1700079730417.png

 

 

Many Thanks

Mike

Hi Ankur,

 

Thank you for the script, I have found it very helpful.

The only issue I have is that the attachment is appearing twice on the request.

Do you know why this would be happening?

 

Feasood_0-1700079730417.png

 

 

Many Thanks

Mike

Uday Soni05
Tera Guru

Hi @Are Kaveri ,

Posting the existing solution provided on Community to resolve your issue

Disable ZZ_YY prefix from attachment when added through record producer

 

I hope this helps you

Please mark this comment as Correct Answer/Helpful if it helped you.
Regards,
Uday