The CreatorCon Call for Content is officially open! Get started here.

How to use the service portal "data" object in a HTML <script> tag

Micael Marinho1
Giga Contributor

Hi guys

I am implementing the google maps API on the portal, however to call it, it is necessary to place the code inside a <script> tag in HTML instead of using the common client script. The problem is that I need to pull information from tables in the servicenow to put on the map, so ideally I would be able to access the data object, from the <script> tag. I tried to use UI script with GlideAjax and the client's GlideRecord, but this type of call just doesn't work from the service portal.

Can someone help me?

I thank you for your attention, have a good day !!!

1 ACCEPTED SOLUTION

Micael Marinho1
Giga Contributor

Hi guys

I was able to solve the problem with the following code:

 

HTML:

<div>
  <script>
    setTimeout(function(){
    	console.log("community: " + top.val);
    }, 10);
  </script>
</div>

Client Controller:

function($scope, spUtil) {
  /* widget controller */
  var c = this;
  top.val = $scope.data.server;
}

Server Script:

(function() {
  /* populate the 'data' object */
  /* e.g., data.table = $sp.getValue('table'); */
  data.server = "test";
})();

The explanation is that when we set the value of "top" in the client controller there is no time for the <script> tag to load it. Then we use the setTimeout() javascript function in the <script> tag to give it a little time.

 

Regards,

Micael Marinho

View solution in original post

16 REPLIES 16

Hi Micael,

 

I'm glad my solution helped you resolve what you desired.

 

Regards

Omkar Mone

Hi Michael,

I am trying to pass the lat and lng parameters to the script tag on receipt of an onclick event.

top.val is not working? Wanted to check if this is something that you have achieved.

Regards,

Anindya