Attach variable inputs to a file and then attach the file to change

jawshoeah
Kilo Contributor

We have a very unique request that I am looking for some advice on. The owner of a Service Catalog item would like the inputs of all the variables on the Service Catalog request form to be exported to a file (csv, excel, pdf, anything) and then have that file automatically attached to the change request that the request item creates in its workflow. Is this something that is even possible? All my research into this topic seems to indicate no, but I wanted to ask the question to a general audience to see if anyone has ever had to do something similar.

Any feedback is welcome. Thanks!

1 ACCEPTED SOLUTION

Michael Ritchie
ServiceNow Employee
ServiceNow Employee

It can be posted as a text file.   There is a workflow activity called Attachment Note that generates an attachment to a record.   You supply it a name and the data and it will create the attachment automatically.



Thinking via typing here...


Since you want this attached to the change record, the Attachment Note activity would need to be in the change workflow.   I assume that parent value of the change_request record is the request and if so you could put a Run Script activity before the Attachment Note activity, loop through all the variables leveraging the parent reference and create the data for the attachment in a workflow scratchpad variable and then use that in the Attachment Note.



There is an OOB script that runs in the request.itil.approve.role email template for catalog request approval emails that may help you get all the variable questions and answers:


var keys = new Array();


var set = new GlideappVariablePoolQuestionSet();    


set.setRequestID(item.sys_id);


set.load();


var vs = set.getFlatQuestions();


for (var i=0; i < vs.size(); i++) {


      if(vs.get(i).getLabel() != '') {


            template.space(4);


            template.print('         ' +   vs.get(i).getLabel() + " = " + vs.get(i).getDisplayValue() + "\n");


      }


}



Obviously the template.print items would need to be replaced by something else, but again this should get you going.


View solution in original post

8 REPLIES 8

This was helpful but doesn't seem to work in my environment.   An attachment with the data values is not being created.   A basic "test" data value works fine, so the workflow appears to be setup correctly.


Michael Ritchie
ServiceNow Employee
ServiceNow Employee

BTW saw your status update on your Notify implementation.   I am leading a lab at K16 on Notify going through all the cool features included in the Geneva release so if you are going, please stop by.   Would love to meet you and hear what you are doing there.


Thank you very much Michael! That was very helpful. I am indeed going out to Knowledge this year, and would love to stop by and chat about how we are using Notify today. I will look for you when I get there


Awesome look forward to meeting you.   I will be spending most of my time in the HackLabs at CreatorCon Most of the week.   Stop by if you cannot make the Advanced Communications (Notify) lab.