How to create PDF file by script from record and attache the file to Record.

kamo1
Tera Contributor
【Script I used】
// This is where we'll save the attachment
var tablename= 'incident';
var recordSysId = 'ed92e8d173d023002728660c4cf6a7bc';
var filename = 'snlogo.png';

 

// Let's download the ServiceNow Logo
var logoUrl =gs.getProperty("glide.servlet.uri") + 'incident' + '.do?PDF&sys_id=' + 'ed92e8d173d023002728660c4cf6a7bc';
gs.info(logoUrl);
var request = new sn_ws.RESTMessageV2();
request.setHttpMethod('get');
request.setEndpoint(logoUrl);

I used this script and it returned 401.
Please let me know what the fix is.

// Configure the request to save the response as an attachment
request.saveResponseBodyAsAttachment(tablename, recordSysId, filename);

 

// When we execute the request, the attachment will automatically be
// saved to the record we specified
var response = request.execute();
var httpResponseStatus = response.getStatusCode();
var httpResponseContentType = response.getHeader('Content-Type');
gs.debug("http response status_code: " + httpResponseStatus);
gs.debug("http response content-type: " + httpResponseContentType);
 
I used this script and it returned 401.
Please let me know what the fix is.
 
thank you all.
1 REPLY 1

Ankur Bawiskar
Tera Patron
Tera Patron

@kamo1 

error 401 means incorrect username and password. please check that once

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