adding resolve button on service portal widget

Community Alums
Not applicable

I was getting the below error when i was written the below code in the widget.can anyone help me with this issue

 

 
 
client script:
 
function() {
  var c = this;
c.uiAction = function(action) {
c.data.action = action;
c.server.update().then(function() {
c.data.action = undefined;
})
}
}
 
Server script:
 
(function() {
 
// Get table & sys_id
data.table = input.table || $sp.getParameter("table");
data.sys_id = input.sys_id || $sp.getParameter("sys_id");
 
// Valid GlideRecord
gr = new GlideRecord(data.table);
if (!gr.isValid())
return;
 
// Valid sys_id
if (!gr.get(data.sys_id))
return;
 
if (input && input.action) {
var action = input.action;
 
// If Incident table
if (data.table == 'incident') {
if (action == 'resolve') {
// Resolve Incident
gr.setValue('incident_state', 6);
gr.setValue('state', 6);
gr.setValue('resolved_by', gs.getUserID());
gr.update();
}
if (action == 'cancel') {
// Do something else
}
}
}
 
})();
 
 
resolve button.png
8 REPLIES 8

Hello @Community Alums 

 

Remove above 2 lines and in Line 8 directly give the name of table in brackets

 

 

Community Alums
Not applicable

@Samaksh Wani Regarding table name ok but the what about the sys_id how should i pass sys_id value

 

Hello @Community Alums 

 

Use this :-

 

 $sp.getParameter("sys_id")

 

for sys_id, directly use it in brackets.

 

Plz Mark my Solution as Accept and Give me thumbs up, if you find it helpful.

 

Regards,

Samaksh

@Community Alums 

check this link and do something similar for resolve

Reopen Incident Button on Service Portal from from Email Notification 

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader