How to call script include in widget client controller.

Naga Surendra 1
Mega Expert

Hi All,

Am trying to call script include in widget client controller. but am getting result value Null.

Client controller :

function($scope) {

  /* widget controller */

  var c = this;

$scope.clearForm = function()

{

var url = $scope.page.g_form.getValue("website_url")

if((url)=='')

{

alert("Website url cannot be blank");

}

else{

var ga = new GlideAjax('inn_rest_function');

  ga.addParam('sysparm_name','getRestDetails');

  ga.addParam('sysparm_url',url);

  ga.getXMLWait();

  var mess = ga.getAnswer();

alert("result"+mess);

$scope.page_form.setValue('website_category',mess);

}

}

}

script include :

var inn_rest_function = Class.create();

inn_rest_function.prototype = Object.extendsObject(AbstractAjaxProcessor, {

getRestDetails: function() {

var r = new RESTMessage('bluecoat', 'post');

var str;

var url_new = this.getParameter('sysparm_url');

gs.log("TESTing " + url_new);

r.setStringParameter('url', url_new);

var response = r.execute();

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

var body = response.getBody().toString();

var json = new JSON();

gs.print( body);

var obj = json.decode(body);

if (obj.unrated == 'false') {

gs.print('this site is unrated');

}

else {

gs.print("TEST " + obj.categorization);

gs.log("from si 5");

var res = obj.categorization;

var strStart = ">";

var strFinish = "</a>";

str = res.match(strStart + "(.*?)" + strFinish);

gs.print(str[1]);

}

}

else {

gs.print('An error occured status code: ' + response.getStatusCode());

}

return str[1];

}

});

please help me how to call script include in client controller.

Regards,

Surendra.

1 ACCEPTED SOLUTION

Chuck Tomasi
Tera Patron

Synchronous Ajax (getXMLWait) is not supported in Service Portal.



Try using getXML() with a callback function. You might be better served through a scripted REST API.


View solution in original post

5 REPLIES 5

Chuck Tomasi
Tera Patron

Synchronous Ajax (getXMLWait) is not supported in Service Portal.



Try using getXML() with a callback function. You might be better served through a scripted REST API.


i changed to getXML() but its not wotking.


I wasn't sure if GlideAjax was supported in widget client scripts. It kind of makes sense that it is not. That's used for the standard forms.



Time to look at a scripted REST API. Your client controller would call it and get the response back. I have an example how I used one with a Service Portal widget in this app:


GitHub - chucktomasi/meetup: Simple meetup app



A full demonstration is available in episode CC17-2 of TechNow


TechNow Episode List


Chuck, I'm from the future and I found this example very useful, does it mean that we need to always use REST API if I want my widget to get data from the server? Is there another way like using GlideAjax?