- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2024 08:24 AM - edited 07-25-2024 08:32 AM
Can someone help me fix this BR so it shows the attachment file ext.
Currently its creating (required) prefix by picking up the value from a field, and creating a new file name as prefix + hyphen + file name. But for some reason not picking up the file extension.
Requirement : The total name character limit is 100 i.e prefix + filename.ext
Business Rule:
(function executeRule(current, previous /*null when async*/ ) {
var auditGR = new GlideRecord(current.table_name);
auditGR.get(current.table_sys_id);
if (auditGR.u_pbc_id) {
current.file_name = auditGR.u_pbc_id + " - " + current.file_name;
}
})(current, previous);
This is what it shows currently in the activity, its missing the file ext.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2024 12:42 PM
@Snow Angel
try this:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2024 08:31 AM
Hi @Snow Angel
business rule you provided is modifying the file name but not appending the file extension. To ensure that the file extension is included, you can update the code to capture and append the extension separately.
(function executeRule(current, previous /*null when async*/) {
var auditGR = new GlideRecord(current.table_name);
auditGR.get(current.table_sys_id);
if (auditGR.u_pbc_id) {
// Get the current file name and extension
var fileName = current.file_name;
var fileExtension = '';
// Extract the file extension
if (fileName.lastIndexOf('.') !== -1) {
fileExtension = fileName.substring(fileName.lastIndexOf('.'));
fileName = fileName.substring(0, fileName.lastIndexOf('.'));
}
// Create the new file name with prefix and extension
current.file_name = auditGR.u_pbc_id + ' - ' + fileName + fileExtension;
// Ensure the total length is within the character limit
if (current.file_name.length > 100) {
var maxFileNameLength = 100 - auditGR.u_pbc_id.length - fileExtension.length - 3; // 3 for " - "
fileName = fileName.substring(0, maxFileNameLength);
current.file_name = auditGR.u_pbc_id + ' - ' + fileName + fileExtension;
}
}
})(current, previous);
Thank You!! Happy learning
……………………………………………………………………………………………………
Please Mark it helpful 👍and Accept Solution✔️!! If this helps you!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2024 08:42 AM
Satish,
I have updated the BR as above but still same result, no file extension is shown.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2024 08:50 AM
Can you debug your code by adding some logs and see if each are getting executed.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2024 08:54 AM
Changed current.table_sys_id to current.sys_id to fetch the current record correctly.
Replaced current.table_name with current.getTableName() to dynamically retrieve the name of the table the current record belongs to.
Make sure the field names like u_pbc_id and file_name are correct and exist on the table