Generate catalog item values in CSV format on submission of catalog item

Angshuman3
Mega Guru

Hi All,

Greetings..!!

I was looking for a solution related to Service Catalog.

We were having a requirement, where we want whatever values we provide on the catalog item form, on clicking on Order Now, the values along with the variable name should get generated in .csv format.

For example,

If there are 2 variable (Name & Age)
and Values entered respectively is (Angshuman & 24)

post this when we click on Order Now, the same information should get generated in .csv format marking Name & Age as to Column names and its values as records entered under each column.

Any leads to this will be very helpful.

Thanks,
Angshuman

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

following script you can add in the workflow attached to the RITM

or have this in after insert business rule on sc_req_item table

give your own file name

this will add a csv file as an attachment to the RITM record

var ritmSysId = current.sys_id;
var set = new GlideappVariablePoolQuestionSet();
set.setRequestID(ritmSysId);
set.load();
var vs = set.getFlatQuestions();

var valuesArray = [];

var csvHeader = [];

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

var variableLabel = vs.get(i).getLabel();

csvHeader.push(variableLabel.toString());

var variableValue = vs.get(i).getDisplayValue();

valuesArray.push(variableValue.toString());

}

var csvHeaderRow = csvHeader.toString();
var valueRow =  valuesArray.toString();
var sa = new GlideSysAttachment();

var document = csvHeaderRow + "\n" + valueRow;

var ritmRec = new GlideRecord('sc_req_item');
ritmRec.get(ritmSysId);

sa.write(ritmRec, "data1.csv", "test/csv", document);

Also posted a blog for the same:

https://community.servicenow.com/community?id=community_blog&sys_id=e4f8bd4edbbc881014d6fb243996190e

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

23 REPLIES 23

Hi Ankur,

Can you please review the below code and let me know if possible.

Thanks,
Angshuman

Hi Angshuman,

Actually didn't get a chance to check on that; will keep you posted

Regards

Ankur

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

Thanks a lot Ankur...!! 

Actually its a bit urgent, so anyways take your time, but please do let know... 🙂

Thanks again,
Angshuman

Hi Anghuman,

just now updated; please check

Regards

Ankur

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

Hi Ankur,

Is there any update in relation to the code which I had provided.

Did you get time to check?

Thanks,
Angshuman