- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-29-2020 04:38 AM
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 !!!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-30-2020 05:40 AM
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-29-2020 10:22 PM
Hi
Just updating the code, in HTML under the script tag use the top object,where you can set the value from the server -
HTML -
<div>
<script>
console.log(top.Val);
</script>
</div>
Client Controller -
function($scope) {
/* widget controller */
var c = this;
top.Val = c.data.valuefromserver;
top.okok = c.data.test111;
}
Server Script -
(function() {
/* populate the 'data' object */
/* e.g., data.table = $sp.getValue('table'); */
data.valuefromserver = "test";
data.test111 = "ok";
})();
Hope this helps.
Regards
Omkar Mone
2020 Community MVP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-30-2020 04:23 AM
Hi
before when I used console.log() pulling a variable from another script, the google maps map didn't even load, now it loads. But when I put the following code:
<div>
<script>
console.log("community: " + top.val);
</script>
</div>
function($scope, spUtil) {
/* widget controller */
var c = this;
top.val = $scope.data.server;
}
(function() {
/* populate the 'data' object */
/* e.g., data.table = $sp.getValue('table'); */
data.server = "test";
})();
The browser console returns this message to me:
"community: undefined"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-30-2020 03:20 AM
Hi,
You can try like this
console.log("test: " + c.data.server);
or
console.log("test: " + $scope.data.server);
Regards,
Arjun
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-30-2020 04:27 AM
Hi
The browser return this to me:
"c is not defined at eval" and
"$scope is not defined at eval"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-30-2020 05:40 AM
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