Server Javascript error Cannot read property “action” from undefined

PaKe
Kilo Sage

Hey,

I created a little widget where I have a Select Box and a button. If I click the button the selected record should be updated.

Unfortunately I always get four error messages when the page is loading. 

find_real_file.png

I'm working in my own Scoped Application but the table is also in this application.

 

HTML Template:

<div class="panel-body">
	<div>
		<b>${Ticket}: </b>
      <select style="width:300px" id='ticket' type='String' class="form-control" ng-model="c.data.tickets">
        <option ng-repeat="ticket in c.data.tickets" value="{{ticket}}">{{ticket}}</option>
      </select>
  		<button style="margin-top:10px" class="btn btn-primary rounded m-l-lg padder-xl" ng-click="c.uiAction('close')">
        	${Close Ticket}
      </button>
  </div>
</div>

 

Client Script:

function() {
  var c = this;
  c.uiAction = function(action){	
		c.data.action = action;
 		c.data.training = document.getElementById('ticket').value;
 		c.server.update().then(function() {
 		c.data.action = undefined;
 		})
 }
}

Server Script:

(function() {
  /* populate the 'data' object */
  /* e.g., data.table = $sp.getValue('table'); */
	data.tickets = [];
	
	var gr = new GlideRecord('x_ntt47_human_care_medical_advice');
		gr.addQuery('state', '1');
		var grOr = gr.addQuery('patient', gs.getUserID());
		grOr.addOrCondition('attending_doctor', gs.getUserID());
		gr.query();
		while(gr.next()){
			data.tickets.push(gr.number.getDisplayValue());
		}
	
	if (input.action == 'close') {
		var gr2 = new GlideRecord('x_ntt47_human_care_medical_advice');
		gr2.addQuery('number', input.ticket);
		gr2.query();
		while(gr2.next()){
			gr2.state = '2';
			gr2.update();
			gs.addInfoMessage('Closed');
		}
	}
})();
10 REPLIES 10

priyankar umesh
Tera Contributor

Yes ! I got the solution . In server script : inside if condition add one more input .So that it will catch weather input exist or not !! (see below)


if (input && input.action == 'close') {
var gr2 = new GlideRecord('x_ntt47_human_care_medical_advice');
gr2.addQuery('number', input.ticket);
gr2.query();
while(gr2.next()){
gr2.state = '2';
gr2.update();
gs.addInfoMessage('Closed');
}
}