How to access data array variable in HTML of widget

tvani
Tera Contributor

Hi,

An array of elements are being set in Server script and accessing that variable elements in the HTML of a widget.

But the elements of the data array are not accessible in HTML. Any suggestion would be of great help.

Please find the below code:

Client Script:

function($rootScope) {

var c = this;

$rootScope.$on("field.change", function(evt, parms) {

if (parms.field.variable_name == 'description') {

c.data.description = parms.newValue;

c.server.update();

}

});

}

Server Script:

data.helpfulKBs = [];

if (input) {

var genpredict = new GENPredict();

var kbArticles = genPredict.getPredictKB(input.description);

if(kbArticles!=""){

var knowledge = new GlideRecord("kb_knowledge");

knowledge.addQuery("number","IN",kbArticles);

knowledge.query();

while(knowledge.next()){

        var article = {

                  'number': knowledge.number,

                  'description': knowledge.short_description

        };

        data.helpfulKBs.push(article);

}

}

data.results = kbArticles;

}

HTML:

${Results: {{c.data.results || ""}}}

<table border="1">

      <tr ng-repeat="article in data.helpfulKBs">

              <td>{{::article.number}}</td>

We are getting the value of c.data.results... but article.number is returning blank value. Can anyone help us on this.

1 REPLY 1

larstange
Mega Sage

Hi



As you are inserting an object (gliderecord) into another object (the "data" object) you must always get the string values, or you will end up with a data object only containing references to another object.



So:


        var article = {


                  'number': knowledge.getValue('number'),


                  'description': knowledge.getValue('short_description')


        };