How to generate excel sheet of variable editor and attach it to requested item.

dj7887
Tera Expert

Hi All,

We have one catalog item and workflow behind it. At one stage of workflow we need to generate Excel sheet of few questions on variabl editor and and attach that excel sheet to current requested item.

Please provide your help on achieving this.

Thanks,

DJ

1 ACCEPTED SOLUTION

Hi Dj,

Figured a way to do this

1) create a scheduled report for Report on Service Catalog Variables; keep it as active false; Run as On demand

Don't set any users in the users field. we don't want email to be triggered to any user; give some unique email Subject

https://docs.servicenow.com/bundle/madrid-performance-analytics-and-reporting/page/use/reporting/con...

2) in the RITM workflow use below script to trigger the scheduled report

var gr = new GlideRecord('sysauto_report');
gr.get('scheduledReportSysId');

// for global scope
SncTriggerSynchronizer.executeNow(gr);

// for custom scope
gs.executeNow(gr);

3) it creates an attachment in sys_attachment table for sys_email table

copy the attachment from that record to your ritm record

Note: one thing to be sure on this is you pick the correct record of sys_email

query sys_email table with that email subject given to scheduled report; orderByDesc() created date and setLimit(1)

sample script

var gr = new GlideRecord('sys_email');

gr.orderByDesc('sys_created_on');

gr.addQuery('subject','Sample Email Subject');

gr.setLimit(1);

gr.query();

if(gr.next()){

GlideSysAttachment.copy('sys_email', gr.sys_id, 'sc_req_item', current.sys_id);

}

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur

 

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

View solution in original post

13 REPLIES 13

Thank you very much Ankur. it worked 🙂

Thanks,

DJ.

Hi Ankur,

How will the report run only for the current RITM? Is it possible to run the scheduled report based on certain condition from the script?

 

Thanks,

Geetha

Hi,

you can use condition with script in scheduled report

Regards
Ankur

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

Hello @Ankur Bawiskar,

I have been trying to get this to work and am having issues. I am running mine from the script section in a INC record Producer and it creates the File but has no data in it. I have a few variables on the form but really am alos only interested in the Variables from a Multi row variable set. How would I get this to work with the following .

 

MRVS = item_information

Variables are:

item_number
correct_average_cost
 
Any help would be greatly appreciated!