The CreatorCon Call for Content is officially open! Get started here.

How to convert URL of a image to image(record) ?

D_R
Giga Guru

We have Servicenow integration with 3rd party tool and getting the response body which contains image information as below

"images" : [ {
"height" : 640,
"url" : "https://i.scdn.co/image/ab67616d0000b273fe74a9fd5050aa4c52017dbc",
"width" : 640
} ],

and we have to attach the image to specific retrieved record. Tried with GlidesysAttachment() but no luck.

1 ACCEPTED SOLUTION

Hitoshi Ozawa
Giga Sage
Giga Sage

Hi Reddy,

I was able to download the jpg file and attach the image to a record using the following script.

var tablename = '<table name>';
var recordSysId = '<record id>';
var filename = '<file name>';
  
try {
    var request = new sn_ws.RESTMessageV2();
	request.setHttpMethod('get');
    request.setEndpoint('https://i.scdn.co/image/ab67616d0000b273fe74a9fd5050aa4c52017dbc');
    request.saveResponseBodyAsAttachment(tablename, recordSysId, filename);
    var response = request.execute();

    httpResponseStatus = response.getStatusCode();

    gs.info(" http response status_code:  " + httpResponseStatus);
} catch (e) {
    gs.info(e.message());
}

Execution result

find_real_file.png

View solution in original post

4 REPLIES 4

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

won't work unless they send the base64encoded data or something else

Just with the URL you cannot do much

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Hitoshi Ozawa
Giga Sage
Giga Sage

Hi Reddy,

I was able to download the jpg file and attach the image to a record using the following script.

var tablename = '<table name>';
var recordSysId = '<record id>';
var filename = '<file name>';
  
try {
    var request = new sn_ws.RESTMessageV2();
	request.setHttpMethod('get');
    request.setEndpoint('https://i.scdn.co/image/ab67616d0000b273fe74a9fd5050aa4c52017dbc');
    request.saveResponseBodyAsAttachment(tablename, recordSysId, filename);
    var response = request.execute();

    httpResponseStatus = response.getStatusCode();

    gs.info(" http response status_code:  " + httpResponseStatus);
} catch (e) {
    gs.info(e.message());
}

Execution result

find_real_file.png

How can I use this code in UI page please provide the code for that.

D_R
Giga Guru

Thank you @Hitoshi Ozawa .