Business Rule Help needed!!

Snow Angel
Tera Expert

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.

SnowAngel_0-1721920855529.png

 

1 ACCEPTED SOLUTION

@Snow Angel 
try this:

 

(function executeRule(current, previous /*null when async*/ ) {
    var auditGR = newGlideRecord(current.table_name);
    auditGR.get(current.table_sys_id);
    if (auditGR.u_pbc_id) {
        var extensionIndex = current.file_name.lastIndexOf(".");
        var extension = current.file_name.substring(extensionIndex);
        var filename = auditGR.u_pbc_id + " - " + current.file_name;
        if (filename.length > 100) {
            filename = filename.substring(0, 100 - extension.length) + extension;
        }
        current.file_name = filename;
    }
})(current, previous);

View solution in original post

12 REPLIES 12

@Snow Angel please check your inbox i have texted you.

@Snow Angel 
try this:

 

(function executeRule(current, previous /*null when async*/ ) {
    var auditGR = newGlideRecord(current.table_name);
    auditGR.get(current.table_sys_id);
    if (auditGR.u_pbc_id) {
        var extensionIndex = current.file_name.lastIndexOf(".");
        var extension = current.file_name.substring(extensionIndex);
        var filename = auditGR.u_pbc_id + " - " + current.file_name;
        if (filename.length > 100) {
            filename = filename.substring(0, 100 - extension.length) + extension;
        }
        current.file_name = filename;
    }
})(current, previous);

@Satishkumar B 

u_pbc_id is a string field and its manually entered and this is the format OIG-001 (xxx-xxx)