Service Portal Widget-working with server script

matthew_magee1
Giga Guru

Hi all,

I'm new to service portal widgets. I've created a simple widget, but am having trouble putting the pieces together. I've looked at some videos and online docs, but am still struggling. So here's my situation:

I want to grab the value selected from a variable on a form and display that in a widget. I've been able to do that w/ the code below using the HTML Template and Client Script. Now what I want to do is to perform some server side calculations and finish up the statement presented to the user regarding shipping. Here is the catalog form:

find_real_file.png

 

Here is my code:

HTML:

<div>
<p>{{ c.data.message }}</p>
</div>

Client Script:

function($scope) {
var c = this;

//Watch for changes in the u_network variable
$scope.$watch(function () {
return $scope.page.g_form.getValue('u_network');
}, function (value) {
//Update local data object with data from variable

if (value){
c.data.message = 'You have selected Network: ' + value +'. Your estimated delivery is: ' + **get value from server script**;
}

});
}


For the server calculation, I want to get the value of the variable (u_network), do a GlideRecord Lookup, and then spit an answer back out to the client to show the delivery time. 

So the finished product would look something like this:

You have selected Network A. Your estimated delivery is 2-3 weeks.

The 2-3 weeks is what I want to pull back from the server script

 

Any help is greatly appreciated!

find_real_file.png

6 REPLIES 6

Thanks for the reply. I too thought about the showFieldMsg but there is just two problems.

 

  1. The number weeks is a calculation and a table look up, something I don't want to do in a client script
  2. I want the message to appear below the title of the variable set. In order for the showFieldMsg to work, I need a field to throw the message under. In my case, all I have a title...no field

 

If you have another suggestion as to how I can use showFieldMsg, I'm all ears

 

Matthew

Ad1) You can always use GlideAjax from client to perform server-side scripting

Ad2) Really depends on the UI requirements. If you prefer to not include a field but rather include another field of type widget depends on you. Anyway, there is another function g_form.setLabelOf that can be used on variables. It is supposed to not work in service catalog, but magically works on service portal. But if the showFieldMsg is not sufficient for you then go ahead with the widget type variable.