
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-30-2019 11:43 PM
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
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-30-2019 11:51 PM
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
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-12-2019 09:01 PM
Hi
I will let you know if there is some other help I require in future in relation this opening a new query.
Again, Thanks a lot.... 🙂
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-04-2025 08:16 AM
Thanks Ankur , Is it possib le to do it in a flat file (.txt) ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-04-2025 08:52 AM
I already replied to your another question and shared the approach.
Do mark my response as correct there and close the thread.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-14-2021 04:36 AM
Hi
Thanks for the solution but there's an issue that I am facing with this statement:
var vs = set.getFlatQuestions();
I think its working fine for some variables, but not for others.
When I log the output of 'vs', it gives me information like -
com.glideapp.questionset.CheckBox
com.glideapp.questionset.Yes/No
com.glideapp.questionset.BreakQuestion
And, this is causing
var variableValue = vs.get(i).getDisplayValue();
this statement to not work properly.
Can you help me with this?