Server Javascript error Cannot read property “action” from undefined
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-11-2021 06:20 AM
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.
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');
}
}
})();

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-11-2021 06:45 AM
Let me try the same code in my PDI and get back to you.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-11-2021 07:45 AM
I tried something on incident table, you can try
HTML
<div class="panel-body">
<div>
<b>${Ticket}: </b>
<select style="width:300px" id='ticket' type='String' class="form-control">
<option ng-repeat="ticket in data.tickets" value="{{ticket}}">{{ticket.number}}</option>
</select>
<button style="margin-top:10px" class="btn btn-primary rounded m-l-lg padder-xl" ng-click="c.uiAction()">
${Close Ticket}
</button>
</div>
</div>
Client Script
api.controller=function() {
/* widget controller */
var c = this;
c.uiAction = function(){
c.data.action = 'close';
//c.data.training = document.getElementById('ticket').value;
c.server.update().then(function() {
c.data.action = '';
})
};
};
Server
(function() {
/* populate the 'data' object */
/* e.g., data.table = $sp.getValue('table'); */
data.tickets = [];
var gr = new GlideRecord('incident');
//gr.addQuery('state', '1');
///var grOr = gr.addQuery('patient', gs.getUserID());
//grOr.addOrCondition('attending_doctor', gs.getUserID());
gr.query();
while(gr.next()){
var a ={}
a.number = gr.number;
data.tickets.push(a);
}
if(input){
if (input.action == 'close') {
var gr2 = new GlideRecord('incident');
//gr2.addQuery('number', input.ticket);
gr2.query();
if(gr2.next()){
gr2.state = '2';
gr2.update();
gs.addInfoMessage('Closed');
}
}
}
})();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-11-2021 07:51 AM
Thank you
Could it be that I get these errors because the widget and the table is in an own scoped application?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-27-2024 06:28 AM
How did you solved this issue ? I am getting same .
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-23-2024 02:58 AM
Hi @PaKe - Were you able to resolve this issue pls?