We're reclaiming inactive PDIs to keep them available for active builders. Learn what's changing, who's affected, and how to protect your work. Read More

How to Download Attachment from URL?

testp21
Tera Contributor

I have done a third party integration. They are sending a URL which, I store in a URL field. Now, how can I download and attach the file in existing record? 

1 ACCEPTED SOLUTION

Not applicable

You can write an async/update BR and use the following script-

(function executeRule(current, previous /*null when async*/ ) {

    var endpointURL = current.u_url;
   var attachmentName = "Attachment Name" + current.number + ".mp4";

    var request = new sn_ws.RESTMessageV2();
    request.setHttpMethod('GET');
    request.setEndpoint(endpointURL);

    request.saveResponseBodyAsAttachment('Table Name', current.sys_id, attachmentName);

    var response = request.execute();

    if (response.getStatusCode() == 200) {
        // Get the response body (file content)
        var responseBody = response.getBody();
    } else {
        gs.error("Failed to retrieve file. HTTP Status Code: " + response.getStatusCode());
    }
})(current, previous);

View solution in original post

2 REPLIES 2

Not applicable

You can write an async/update BR and use the following script-

(function executeRule(current, previous /*null when async*/ ) {

    var endpointURL = current.u_url;
   var attachmentName = "Attachment Name" + current.number + ".mp4";

    var request = new sn_ws.RESTMessageV2();
    request.setHttpMethod('GET');
    request.setEndpoint(endpointURL);

    request.saveResponseBodyAsAttachment('Table Name', current.sys_id, attachmentName);

    var response = request.execute();

    if (response.getStatusCode() == 200) {
        // Get the response body (file content)
        var responseBody = response.getBody();
    } else {
        gs.error("Failed to retrieve file. HTTP Status Code: " + response.getStatusCode());
    }
})(current, previous);

It worked! Thanks for quick support.