Generating PDF of the prefilled catalog variables and attach to request(sc_req_item) after submit the catalog item and send an email to the user ABC.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-07-2020 04:44 AM
Hi,
Generating PDF of the prefilled catalog variables and attach to request(sc_req_item) after submit the catalog item and send an email to the user ABC.
I came across a workflow script :
var varquestion='';
var varanswer='';
var itemjoin="";
var itemquestion = "";
var itemanswer='';
var v;
/* Put all variable values and labels from the variable pool into an array */
var sortedArray = sortVariables(current.variables); gs.log("@@@insiderresult sortedArray: "+sortedArray);
for (var i in sortedArray) {
v = current.variables[sortedArray[i].index];
/* Only include non-empty variables, and exclude Label and Container variables */
if (v != '' && v != 'false' && v.getGlideObject().getQuestion().type != 11 && v.getGlideObject().getQuestion().type != 19 && v.getGlideObject().getQuestion().type != 20) {
itemquestion += v.getGlideObject().getQuestion().getLabel() + ":"+ v.getDisplayValue();
}
}
varquestion += itemquestion;
var finaloutput=varquestion; gs.log("@@@insiderresult finaloutput: "+finaloutput);
function sortVariables ( variableArray ){
var sortedVariables = [];
var count = 0;
for ( var i in variableArray ){
var object = {index:i, order:variableArray[i].getGlideObject().getQuestion().order};
sortedVariables[count] = object;
count++;
}
sortedVariables.sort( function compare(a,b){return a.order - b.order});
gs.log("@@@insiderresult Sortvariables: "+sortedVariables);
return sortedVariables;
}
//converts the file to xls format with file name as RITM number (considering workflow is on RITM table) & is attached to the RITM record
var attachfile = new GlideSysAttachment();
attachfile.write(current, current.number+'.pdf','application/pdf', finaloutput);
Fault description: TypeError : line 31( var object = {index:i, order:variableArray[i].getGlideObject().getQuestion().order};) showing "can't convert null to an object"
any help on this is really appreciated.
Thank you,
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-07-2020 05:18 AM
Hi Abhishek,
refer my blog below and it should help you; it is for csv file but you can enhance it for xls
Generate csv file with the catalog variables and attaching to RITM record
Regards
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
09-07-2020 09:23 AM
Thank you !!
will this approach for the custom table to get variables and attach to the request using BR after insert.
if yes, please let me know how that can be achieved.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-07-2020 05:21 AM
Hi,
I believe you are referring to this blog
https://community.servicenow.com/community?id=community_blog&sys_id=24595f84db886b40fece0b55ca9619a5
that would help for excel file generation
But for generating pdf file would require to either use Printer friendly version or use custom code
refer below links for help
printer friendly version -
custom code
Regards
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
09-07-2020 09:06 AM
Thank you for your valuable response.
As per my requirement was to include the variable sets and catalog variables present on the form.but above functionality will work only for the variables on the form.
please let me know if is there any ways to get variable sets value including form variables into the pdf and attach to the request.
help on this is really appreciated.