User with snc_internal cannot open attachments sent via email from the system.

Michael_Nash
Tera Contributor

I have a notification that gets sent to 2 users in the accounting team the attachment is a txt file and when the try open it the get directed to ServiceNow and told they don't have access.

 

They just need to be able to click it and download it to their pc's to open the attachment. 

7 REPLIES 7

Kieran Anson
Kilo Patron

Are these attachments on the record that the email is related to? Can the "send attachments" be used?

 

If you're linking to an attachment record, they'll require to pass authentication and then the authorization (ACLs)

Hi @Kieran they are attachment is generated from a Scheduled job. 

 

var GR_Warranty = new GlideRecord('sn_customerservice_warranty');
GR_Warranty.addEncodedQuery('state=9');//Approved and Awaiting Payment
GR_Warranty.query();
var contenttype = '';
var sys_id;
var payable;
while (GR_Warranty.next()) {
    GR_Warranty.state = '20';//Approved for Payment
    GR_Warranty.update();
    var accountNo, subaccountNo, kmbo;

    if (GR_Warranty.u_claim_type == 'campaign') {
        accountNo = '22615';
        subaccountNo = '7050';
        kmbo = '600';
    } else if (GR_Warranty.u_claim_type == 'emissions') {
        accountNo = '22615';
        subaccountNo = '7010';
        kmbo = '600';
    } else if (GR_Warranty.u_claim_type == 'extWarranty') {
        accountNo = '22620';
        subaccountNo = '7010';
        kmbo = '600';
    } else if (GR_Warranty.u_claim_type == 'fixAsFail') {
        accountNo = '22615';
        subaccountNo = '7010';
        kmbo = '600';
    } else if (GR_Warranty.u_claim_type == 'goodwill') {
        accountNo = '22615';
        subaccountNo = '7030';
        kmbo = '607';
    } else if (GR_Warranty.u_claim_type == 'inTransit') {
        accountNo = '22615';
        subaccountNo = '7010';
        kmbo = '600';
    } else if (GR_Warranty.u_claim_type == 'Misbuild') {
        accountNo = '22615';
        subaccountNo = '7010';
        kmbo = '600';
    } else if (GR_Warranty.u_claim_type == 'PDIRepair') {
        accountNo = '22615';
        subaccountNo = '7010';
        kmbo = '600';
    } else if (GR_Warranty.u_claim_type == 'pdi') {
        accountNo = '22615';
        subaccountNo = '7020';
        kmbo = '601';
    } else if (GR_Warranty.u_claim_type == 'pdr') {
        accountNo = '22615';
        subaccountNo = '7010';
        kmbo = '600';
    } else if (GR_Warranty.u_claim_type == 'warrantyRepair') {
        accountNo = '22615';
        subaccountNo = '7010';
        kmbo = '600';
    }
    //get date only from created time and date
    var gdt = new GlideDateTime(GR_Warranty.sys_created_on);
    var gc = gdt.getDate();
    var createdDate = gc.getByFormat("MM/dd/yyyy");
    //format repair date to mm/dd/yyy
    var date = GR_Warranty.getValue('u_date_repair_completed');
    var gd = new GlideDate();
    gd.setValue(date);
    var repairDate = gd.getByFormat("MM/dd/yyyy");

    // Determine the amount based on currency
    var amount;

    if (GR_Warranty.u_currency == 'CAD') {
        var dollar = parseFloat(GR_Warranty.u_usd_dollar_amount);
        dollar = dollar.toFixed(2);

       
        amount = dollar;
    } else {
        var claimAmount = parseFloat(GR_Warranty.u_approved_claim_amount);
        claimAmount = claimAmount.toFixed(2);
        amount = claimAmount;
    }

    contenttype = GR_Warranty.u_dealer_code + '\t' + GR_Warranty.u_account_name + '\t' + GR_Warranty.number + '\t' + repairDate + '\t' + createdDate + '\t' + GR_Warranty.u_vin + '\t' + "$" + amount + '\t' + 'WAR' + '\t' + accountNo + '\t' + subaccountNo + '\t' + '\t' + 'USD' + '\t' + '1' + '\t' + '\t' + '\t' + '\t' + '\t' + kmbo + '\n' + contenttype;
    sys_id = GR_Warranty.sys_id;
    var dte = gs.nowDateTime();
    dte = dte.toString().split(" ")[0];
    var parts = dte.split('-');
    var year = parts[0];
    var month = parts[1];
    var day = parts[2];

    var formattedDate = month + '_' + day + '_' + year;

    var fileName = "payables_" + formattedDate + ".txt";

    payable = fileName;
}

var attach = new Attachment();
attach.write('sn_customerservice_warranty', sys_id, payable, '.txt', contenttype);
attach.insert();
if (contenttype != '') {
    gs.eventQueue("sn_customerservice.Warranty Claim Global", current, gs.getUserID(), gs.getUserName());
}

Hi,

So I assume 'sn_customerservice.Warranty Claim Global' event is triggering a notification. Does that have some sort of mail script to create links within the email body?

Yes it has,

 

${mail_script:add.attachment}

 

which is this, 

 

(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,
    /* Optional EmailOutbound */
    email, /* Optional GlideRecord */ email_action,
    /* Optional GlideRecord */
    event) {
    gs.info('ST://123456');
    var dte = gs.nowDateTime();
    dte = dte.toString().split(" ")[0];
    var parts = dte.split('-');
    var year = parts[0];
    var month = parts[1];
    var day = parts[2];
    var formattedDate = month + '_' + day + '_' + year;

    var fileName = "payables_" + formattedDate + ".txt";
    gs.info('ST://123456'+fileName);
    var GR_attachment = new GlideRecord('sys_attachment');
    GR_attachment.addQuery('file_name',fileName);
    GR_attachment.orderByDesc('sys_created_on');
    GR_attachment.query();
    if(GR_attachment.next()){
        gs.info('ST://Thakur'+GR_attachment.sys_id);
        var link = "<a href = /sys_attachment.do?sys_id=" + GR_attachment.sys_id + ">" + GR_attachment.file_name + "</a>" ;
template.print(link);

    }

})(current, template, email, email_action, event);