
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-19-2020 12:37 AM
Hi
i want to create a one PDF file for incident record and that pdf file will attach to same incident record. Is there any way to do.
Please can you suggest me where i am wrong,
This is the Script Which i am Using in Workflow after insert business rules:
(function executeRule(current, previous /*null when async*/) {
// attachment.write('tablename', recordsysid, fileName, content_type, fileDate);
// "attachment" is the object variable of Attachment() type
// "tablename" is string variable that contains the name of the table where you want to attach the file.
// "recordsysid" is the sys id of the record where you want to attach the file
// "filename" is the file name of the attachment
// "content_type" is the type of content in the file (usually for pdf it is 'text/text')
// "fileData" contains the data that you want to put in the file.
// Example: Business Rule to run after insert
var tableName = "incident"; //incident Item Table
gs.addInfoMessage("Table Name :"+tableName);
var recordsysid = current.sys_id; //sys id of the record
gs.addInfoMessage("RecordSysID :"+recordsysid.getDisplayValue() +" == "+recordsysid);
var fileName = current.number+" FormData.pdf";
gs.addInfoMessage("file Name :"+fileName);
var content_type = 'text/pdf';
gs.addInfoMessage("content_type :"+content_type);
var fileData=""; // Declare an empty string
fileData+=current.number+" "+current.short_description+"</ b>"; // current access the varibles in the record
//fileData+=current.variables.u_requested_for.getDisplayValue()+"</ b>"; // current.variables access the variables or fields in the form or catalog Item
fileData+=current.state+"</ b>";
fileData+=current.variables.u_department.getDisplayValue();
gs.addInfoMessage("File Data :"+fileData);
var attachment = new Attachment();
attachment.write('tablename', recordsysid, fileName, content_type, fileDate);
})(current, previous);
I am getting these values but not attaching the Attachments in the records :
I am getting some help from one thread but its not working
Thanks in advance.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-19-2020 01:56 AM
rest message should also fulfill this requirement.
try with below code.
Script include:
var CreateAttachments = Class.create();
CreateAttachments.prototype = {
initialize: function() {
},
creatAttch: function(name,contentType, data){
var attCreator = new GlideRecord('ecc_queue');
attCreator.agent = "AttachmentCreator";
attCreator.topic = "AttachmentCreator";
attCreator.name = "pdf" + ":" + contentType;
attCreator.source = current.getTableName()+":"+current.sys_id;
attCreator.payload = data;
attCreator.insert();
},
type: 'CreateAttachments'
};
Business rule:
(function executeRule(current, previous /*null when async*/) {
var fileName = current.number+" FormData.pdf";
var fileData=""; // Declare an empty string
fileData+=current.state+"</ b>";
fileData+=current.short_description.getDisplayValue();
var ab = new CreateAttachments().creatAttch(fileName,'application/pdf', fileData);
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-22-2022 11:45 AM
Hello Sanjay
Did you find a resolution for this? Im getting the same error
Steve
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-28-2022 12:09 PM
Hi
I tried below code , even i m getting same error like below.
what might be issue. how can we resolve it .
SCRIPT Include :
var CreateAttachments = Class.create();
CreateAttachments.prototype = {
initialize: function() {},
creatAttch: function(name, contentType, data) {
var attCreator = new GlideRecord('ecc_queue');
attCreator.agent = "AttachmentCreator";
attCreator.topic = "AttachmentCreator";
attCreator.name = name + ":" + contentType;
attCreator.source = current.getTableName() + ":" + current.sys_id;
attCreator.payload = data;
attCreator.insert();
},
type: 'CreateAttachments'
};
Business rule :
(function executeRule(current, previous /*null when async*/ ) {
var arr = [];
var results = '';
var gr = new GlideRecord('asmt_metric_result');
gr.addQuery('instance', '982a2c44d7211100158ba6859e6103a4');
gr.query();
var count = gr.getRowCount();
gs.print(count);
while (gr.next()) {
arr.push(gr.metric.name.toString()+"</ b>");
arr.push(gr.string_value+"</ b>");
}
gs.print(arr);
results = arr.join("\n");
gs.info("results :" + results);
var fileName = current.number + " FormData.pdf";
var ab = new CreateAttachments().creatAttch(fileName, 'application/pdf', results);
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-28-2022 12:24 PM
Hi
did you get any solution to create PDF?
even i m getting same error like file error.
script include :
var CreateAttachments = Class.create();
CreateAttachments.prototype = {
initialize: function() {},
creatAttch: function(name, contentType, data)
{
var attCreator = new GlideRecord('ecc_queue');
attCreator.agent = "AttachmentCreator";
attCreator.topic = "AttachmentCreator";
attCreator.name = "Replys" + ":" + contentType;
attCreator.source = current.getTableName() + ":" + current.sys_id;
attCreator.payload = data;
attCreator.insert();
},
type: 'CreateAttachments'
};
Business rule :
(function executeRule(current, previous /*null when async*/ ) {
var arr = [];
var results = '';
var gr = new GlideRecord('asmt_metric_result');
gr.addQuery('instance', '982a2c44d7211100158ba6859e6103a4');
gr.query();
var count = gr.getRowCount();
gs.print(count);
while (gr.next()) {
arr.push(gr.metric.name.toString() + "<br>" + "<br>");
arr.push(gr.string_value + "<br>" + "<br>");
}
gs.print(arr);
results = arr.join("\n");
gs.info(results);
var fileName = current.number + " FormData.pdf";
var ab = new CreateAttachments().creatAttch(fileName, 'application/pdf', results);
})(current, previous);