Attachement name and format is undefined when it is attaching to the case
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-11-2024 02:35 AM
Hello experts,
I used the below script to generate the CSV file using a BR but the attachment was undefined when it is attaching to the case.
@asifnoor Could you please check the code once and help us to proceed further.
Please find the below script that I used.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-11-2024 03:52 AM
try Updating the CSV construction to use join(',') to properly format the data.
my code :
(function executeRule(current, previous /*null when async*/) {
// Define the CSV Headers and initialize the CSV data variable
var Headers = ["Number", "Record Type", "Field 0021", "Field 015", "Field 2010", "Trail", "User ID", "Personnel Number", "Contact Name", "Country ISO", "File Name", "Infotype Operation", "Interface Run Date", "Infotype 0221", "Interface Run Time", "Subtype", "Run Type", "Start Date", "Version Number", "End Date", "Currency Key", "Wage Type", "Wage Type Amount", "Record Count"];
var fileName = 'ADP11.csv';
var csvData = Headers.join(',') + '\r\n'; // Join headers with commas for CSV format
// Query the relevant records to include in the CSV
var gr = new GlideRecord("xxxxxxxx"); // Replace xxxxxxxx with the correct table name
gr.addQuery("u_parent_hr_case_no", current.number);
gr.query();
// Loop through the results and build CSV rows
while(gr.next()) {
var row = [
gr.u_gg_int_record_type,
gr.u_gg_int_record_type_0021,
gr.u_gg_int_record_type_015,
gr.u_gg_int_record_type_2010,
gr.u_gg_int_record_type_trail,
gr.u_gg_user_id,
gr.u_previous_personnel_number,
gr.u_contact_name,
gr.u_country_iso_code,
gr.u_gg_int_file_name,
gr.u_infotype_operation,
gr.u_gg_interface_run_date,
gr.u_infotype_0221,
gr.u_gg_interface_run_time,
gr.u_subtype,
gr.u_run_type,
gr.u_start_date,
gr.u_version_number,
gr.u_end_date,
gr.u_currency_key,
gr.u_wage_type,
gr.u_wage_type_amount_for_payments,
gr.u_record_count
].join(','); // Join fields with commas for CSV format
csvData += row + '\r\n';
}
// Attach the file to the record
var grRec = new GlideRecord("xxxxxxxxxxx"); // Replace xxxxxxxxxx with the correct table name for the case
grRec.addQuery("u_parent_hr_case_no", current.number);
grRec.query();
if(grRec.next()){
var grAttachment = new GlideSysAttachment();
grAttachment.write(grRec, fileName, 'application/csv', csvData); // Attach CSV data as a file
gs.info("CSV file attached successfully: " + fileName); // Log success for debugging
} else {
gs.error("Failed to find record to attach CSV.");
}
})(current, previous);
Accept and hit Helpful if it helps.
Best Regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-12-2024 05:18 AM
Hi @New Developer_S ,
Can we add multiple field names in each row of the attachment for each record.
Thanks,
Uday Kumar