NG-IF not working on widget as expected - Reopening ticket widget

Edxavier Robert
Mega Sage

Hi all, 

I just create a new widget to allow users to reopen tickets over the Service Portal (San Diego). But I wanted to only show the widget on incidents that are in the resolved state. My issue is that every time I add the ng-if into the html code the widget never shows up. 

Here is the HTML code

 

 

<div>
<!-- your widget template -->
  <div class="panel panel-default" ng-if= "c.data.showWidget">
 <div class="panel-heading bg-primary panel-la-jola-default">Incident is not resolved?</div>
 <div class="panel-body">
 <button type="button" class="btn btn-primary btn-block" ng-click="c.uiAction('reOpen')">Re-Open Incident</button>
  </div>
</div>

 

 

 

Here the Client Script Code

 

 

function($scope, spUtil) {
  var c = this;
spUtil.recordWatch($scope, $scope.data.table, "sys_id=" + $scope.data.sys_id);
		
 c.uiAction = function(action) {
if(!confirm('Are you sure you want to re-open the incident?')) return;
c.data.action = action;
c.server.update().then(function() {
c.data.action = undefined;
})
}
}

 

 

 

Here is the Server Script code:

 

 

(function() {
  /* populate the 'data' object */
  /* e.g., data.table = $sp.getValue('table'); */
	
	
	// Get table & sys_id
 data.table = input.table || $sp.getParameter("table");
 data.sys_id = input.sys_id || $sp.getParameter("sys_id");
 
 // Valid GlideRecord
	var Incident = [];
 gr = new GlideRecord(data.table);
 if (!gr.isValid())
 return;
 
 // Valid sys_id
 if (!gr.get(data.sys_id))
 return;
	
//Button Visibility
data.state = gr.getValue('state');
data.showWidget = (data.state == '6') ? true: false;

 
 if (input && input.action) {
 var action = input.action;
 
 // If Incident table
 if (data.table == 'incident') {
 if (action == 'reOpen') {
 // Resolve Incident
 gr.setValue('incident_state', 2);
 gr.setValue('state', 2);
 gr.setValue('sys_updated_by', gs.getUserID());
 gr.update();
 } 
 }
 }

})();

 

 

 

4 REPLIES 4

-O-
Kilo Patron
Kilo Patron

I'm not saying this must be the root cause for the ngIf not playing along, but you have an undeclared variable gr in there. Try placing a var before it - to prevent "hijacking" some global context variable.

Hi, I tried that but still not working. 

Kirby R
Kilo Sage

You lack one end tag </div>.

Hi, I removed the extra <div>, but still doesn't work in San Diego. Same code is currently working in Rome.