The Zurich release has arrived! Interested in new features and functionalities? Click here for more

Input on server script is undefined on c.server.update()

johnny27
Tera Contributor

One of my work instances, the input variable on the server script remains undefined instead of being updated to a catalog item sys id whenever the select picker changes value. The correct behavior should list the name of the catalog item below the select option.

Build date: 07-16-2017_1252

Build tag: glide-istanbul-09-23-2016__patch7-hotfix1-07-15-2017

MID buildstamp: istanbul-09-23-2016__patch7-hotfix1-07-15-2017_07-16-2017_1252

Load-balancer status: Online

HTML

<div class="row">

      <div class="col-sm-12">

              <select ng-change="selectCatItem()"

                              ng-model="c.data.selectedCatItem"

                              ng-options="catItem.sys_id as catItem.short_description for catItem in c.data.catItemList">

              </select>

      </div>

</div>

<div class="row">

  <div class="col-sm-12">

      {{c.data.curCatItem.short_description}}

  </div>

</div>

Client Script

function($scope) {

  /* widget controller */

  var c = this;

$scope.selectCatItem = function() {

console.log("onSelect",c.data.selectedCatItem);

c.server.update();

}

}

Server Script:

(function() {

  /* populate the 'data' object */

  /* e.g., data.table = $sp.getValue('table'); */

var catItemGR = new GlideRecord('sc_cat_item');

catItemGR.addActiveQuery();

catItemGR.addNotNullQuery('short_description');

catItemGR.setLimit(5);

catItemGR.query();

data.catItemList = [];

while(catItemGR.next()) {

var n = {};

$sp.getRecordValues(n, catItemGR, 'sys_id,name');

data.catItemList.push($sp.getCatalogItem(catItemGR.sys_id));

}

gs.log(input,'ss_init');

console.log(input.selectedCatItem);

if(input.selectedCatItem!=undefined){

console.log("FOUND");

data.curCatItem = $sp.getCatalogItem(input.selectedCatItem);

}

})();

input returns undefined in the syslog every time the select option changes value.

1 ACCEPTED SOLUTION

Rushit Patel2
Tera Guru

not sure if it would make any difference but try to move line 17 to 20 to top of the server script.



it shouldnt make any difference but i have seen some wierd behavior.



(please mark helpful/like/correct if it helps)


View solution in original post

8 REPLIES 8

Rama Chandra D
Kilo Guru

HI Johnny,



Input is the data object sent from client script and looking at your client script, the selectedCatItem is never populated in first place. So, when you call server update from client script, the sever script doesn't have any value or the input object doesn't even have an attribute called 'selectedCatItem'.



Do you want to display the items in catItemList on console? What are you trying to achieve?



Best,


Darshak


So when it's working, when the user selects a catalog item from the dropdown, the catalog item's short description should appear below it.



On the initial load, it makes sense that it's not defined and that's okay. However, after an option is selected from the dropdown, the server script should receive a sysid from input.selectedCatItem and use it to define data.curCatItem as that catalog item.



On my work instance where it's broken, it still returns as undefined after a dropdown option is selected. However, on my personal dev instance,   the widget works properly and I can see the short description appear under the dropdown.


HI Johnny,



Thanks for the clarification. Let me look at it. The code works fine on my Jakarta instance too.



Best,


Darshak


Rushit Patel2
Tera Guru

not sure if it would make any difference but try to move line 17 to 20 to top of the server script.



it shouldnt make any difference but i have seen some wierd behavior.



(please mark helpful/like/correct if it helps)