Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Why data.variable not displaying data in widget?

Ankita Kolhe
Tera Contributor

Hi Community,

 

I have two widgets, in which first widget contains text box & search button. When user clicks on Search button, the another widget displays table.

But data is not displaying on table.It seems some issue with - data.gisid & data.location.

However, logs are displaying correctly.

 

AnkitaKolhe_0-1705908979244.png

 

 

 

Widget 1 html code:-

<span class="col-md-7"><input id="search_term" name="search_term" type="search" placeholder="Enter Name,GIS ID or DUNS" class="form-control input-md"></span> 

<div class="each-pill" ng-class="{'active':c.selectedPill == 'entitytable'}" ng-click="selectPill('entitytable')">

<a type="button" ng-click="c.searchEntityREST()" class="btn btn-primary">${Search Entity}</a>

</div>

 

Widget 2:-

 

Html code:-

<table class="table table-striped">
<thead>
<tr>
<th>GIS Entity ID</th>
<th>Entity Name</th>
<th>Entity Location</th>
<th>Entity Type</th>
</tr>
</thead>
<tbody>
<tr ng-if="data.gisid!='"> 
<td>{{data.gisid}}</td>
<td>{{data.location}}</td>
</tr>
</tbody>
</table>

 

Server Script:-

 

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

    var arr = [];

    if (input && input.action == "callSearchEntity") {

        gs.info('arr');
        gs.info('test server side');
        gs.info('input: ' + input.search_term);
        var dat = new x_kpm79_kpmgi_cto.CTOEntityManagementUtils().triggerRESTMessage('global.sentinel''GetEMEntities', input.search_term);
        gs.info('returned dat: ' + dat);
        arr = dat.split(',');
        gs.info('arr[0]: ' + arr[0]);
        gs.info('arr[1]: ' + arr[1]);

    }
    data.gisid = arr[0];
    data.location = arr[1];
   
     gs.info('arr[0] out: ' + arr[0]);
     gs.info('arr[1] out: ' + arr[1]);

})();
 
Client Script:-
 
api.controller=function(spUtil,$scope,spModal,$timeout) {
   
    /* widget controller */
    var c = this;

    $scope.showWidget = "";

  $scope.$on('showHideWidget'function(event,d,obj) {

  $timeout(function(){

    c.server.get({
            action:"callSearchEntity",
            search_term:obj.search_term,
            //country:document.getElementById('country').value
        });
    alert(obj.search_term);
  $scope.showWidget = d;

  });

  });

};
 
logs:-
AnkitaKolhe_1-1705908979256.png

 

 

 
Could anyone please help on this?
5 REPLIES 5

Just to check, I see you have some log lines in your server script. I assume these are printing the data you expect?

In which case it could well be the call back not updating properly. I would try this.

 

Server Script

data.gisid = arr[0].toString();
data.location = arr[1].toString();

 

Client Script

/* widget controller */
    var c = this;

    $scope.showWidget = "";
    $scope.

    $scope.$on('showHideWidget', function(event, d, obj) {

        $timeout(function() {

             c.server.get({
                action: "callSearchEntity",
                search_term: obj.search_term,
            }).then(function(response) {
                $scope.gsid = response.gsid;
	        $scope.location = response.location;
            });
            alert(obj.search_term);
            $scope.showWidget = d;

        });

    });

 

HTML

<td>{{.gisid}}</td>
<td>{{location}}</td

 

This adds a callback function to the client call and populates some client side variables. In turn these variables are used in the script.

 

The above is untested - I believe the syntax is correct on the callback.