how to call ui macro from business rule or script include or scheduled job?

Community Alums
Not applicable

Hi Can any one help me on this issue,

how to call ui macro from server side script.

thanks,

Rajendra Prasad Darshanam

1 ACCEPTED SOLUTION

I did some research into this and it looks like using GlideHTTPRequest() can be difficult if the content type is Binary due to issues between Java and JavaScript. I found another post here on Community which suggests using the RESTMessageV2() Class instead. I was successfully able to download Chuck's avatar image using the following (note I used an Incident record as the target for the attachment):



var url = 'https://community.servicenow.com/people/ctomasi/avatar/80.png?a=7252';


var rm = new sn_ws.RESTMessageV2();


rm.setEndpoint(url);


rm.setHttpMethod('get');


rm.saveResponseBodyAsAttachment('incident', 'd71f7935c0a8016700802b64c67c11c6', 'chuck_image.png'); // update target details here


var response = rm.execute();


if(response.getStatusCode()==200) {


        // Success!


}



More information is available on the Product Documentation site regarding this function. Note that it is only available from Geneva onwards.


View solution in original post

13 REPLIES 13

Community Alums
Not applicable

I want to convert image url to base64 bytes


You could try using GlideHTTPRequest() to get the binary and then convert it to Base64.



Try this script (it should download the avatar for ctomasi😞



var url = 'https://community.servicenow.com/people/ctomasi/avatar/80.png?a=7252';


var httpReq = new GlideHTTPRequest(url);


var response = httpReq.get();


try {


  var data = response.getBody();


  var base64data = GlideStringUtil.base64Encode(data);


  gs.log(base64data);


} catch (err) {


  gs.log('Error making HTTP Request: ' + err);


}


Community Alums
Not applicable

thanks Jake,


but when i am saving the base64data to ecc_queue table its not


showing image.




On Tue, Sep 27, 2016 at 10:34 AM, jake.gillespie <


I'm not sure of your entire requirement (as ctomasi said it would be helpful to understand this), but you might need to pipe the base64 data into the Attachment creator API so you can create the file as an attachment. Once the file is an attachment, you should be able to include it on a page (e.g. HTML element) to see it.



Regards,


Jake


Community Alums
Not applicable

Thanks Jake,


here is the code which i have,



var httpReq = new GlideHTTPRequest(url);


var response = httpReq.get();


var data = response.getBody();


var base64data = GlideStringUtil.base64Encode(data);



var sourceString = "tablename:recordSysId";


var eccQueue = new GlideRecord('ecc_queue');


eccQueue.initialize();


eccQueue.topic = "AttachmentCreator";


eccQueue.agent = "AttachmentCreator";


eccQueue.payload=;base64data


eccQueue.name="columnName:image/jpeg";


eccQueue.source= sourceString;


//eccQueue.insert();



but image is not showing in the record.



On Tue, Sep 27, 2016 at 2:50 PM, jake.gillespie <