Error - Cant find method com.glide.ui.SysAttachment
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-07-2024 06:09 AM
Below script i written in scripted rest API but not working as expected.
{
"error": {
"message": "Script Evaluation Exception",
"detail": "Can't find method com.glide.ui.SysAttachment.write(string,string,string,string,org.mozilla.javascript.ConsString). (sys_ws_operation.9708d678c3130210be043bec0501314a.operation_script; line 23)"
},
"status": "failure"
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-07-2024 06:35 AM - edited 07-07-2024 06:39 AM
Hi @Rama26 ,
The 'GlideSysAttachment - write' takes 4 parameter as below:
GlideSysAttachment - write(GlideRecord record, String fileName, String contentType, String content)
SN Doc: GlideSysAttachment - Global
So, after updating it will be as below:
(function process( /*RESTAPIRequest*/ request, /*RESTAPIResponse*/ response) {
var incidentNumber = 'INC0009009';
var grIncident = new GlideRecord('incident');
grIncident.addQuery('number', incidentNumber);
grIncident.query();
if (grIncident.next()) {
var shortDescription = grIncident.getValue('short_description');
var priority = grIncident.getValue('priority');
var state = grIncident.getValue('state');
var assignedTo = grIncident.getDisplayValue('assigned_to'); // Using getDisplayValue to get the display name
var csvContent = "ShortDescription,Priority,State,AssignedTo\n";
csvContent += '"' + shortDescription + '","' + priority + '","' + state + '","' + assignedTo + '"\n';
// var attachment = new GlideSysAttachment();
// var excelFileSysID = attachment.write(grIncident, 'incident_data.csv', 'text/csv', csvContent);
gs.info('CSV file created with sys_id: ' + excelFileSysID);
} else {
gs.info('No incident found with number ' + incidentNumber);
}
})(request, response);
Output:
Mark this as Helpful / Accept the Solution if this helps
Mark this as Helpful / Accept the Solution if this helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-07-2024 07:28 AM
Thanks @Rama26 for marking as helpful.
If it resolved your query please consider marking 'Accept as solution' and close the thread.
Mark this as Helpful / Accept the Solution if this helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-07-2024 07:34 AM
for CSV it's working but i need to attach xlsx file
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-07-2024 08:34 AM
Hi @Rama26 ,
Try the below suggested KB
Attach an excel file on a record by making REST API call to ServiceNow Excel Web Service
Mark this as Helpful / Accept the Solution if this helps
Mark this as Helpful / Accept the Solution if this helps.