Scriptes Rest API to create record and add attachment to record
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-02-2024 11:09 PM - edited 10-03-2024 12:30 AM
Hi,
I tried to created scripted rest api to create a record and attach attachment to that record, but attachemnt is added to attachment table and record as undefined.
(function process( /*RESTAPIRequest*/ request, /*RESTAPIResponse*/ response) {
var requestBody = request.body.dataString;
var parser = new global.JSON();
var parsedData = parser.decode(requestBody);
//var number = parsedData.incidentNumber;
var fileName = parsedData.fileName;
var fileContentType = parsedData.contentType;
var base64EncodedContent = parsedData.content;
var regularContent = GlideStringUtil.base64DecodeAsBytes(base64EncodedContent);
var rec = new GlideRecord('u_new_hire_termination_import');
rec.initialize();
rec.u_name = "Workday Request";
rec.insert();
var sa = new GlideSysAttachment();
//var decodedString = GlideStringUtil.base64Decode(fileData);
sa.write(rec, fileName, fileContentType,regularContent);
var responseBody = {};
responseBody.incNumber = rec.number;
responseBody.status = "Success";
response.setBody(responseBody);
})(request, response);
Thanks in advance,
Sneha
2 REPLIES 2
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-02-2024 11:41 PM
Hi Sneha,
There is a statement with syntax error at gs.log line. Remove this line or edit to
gs.log('File name' +fileName);
Regards, Akash
If my response proves useful, please mark it "Accept as Solution" and "Helpful". This action benefits both the community and me.
If my response proves useful, please mark it "Accept as Solution" and "Helpful". This action benefits both the community and me.
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2024 12:30 AM
Hi Akash,
I tried it but still its adding attachment as undefined text file.
Thanks,
Sneha