- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-01-2017 07:17 AM
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.
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-01-2017 07:22 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-01-2017 07:22 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-01-2017 07:36 AM
i changed to getXML() but its not wotking.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-01-2017 07:40 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-14-2019 08:24 PM
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?