Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

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

Samaksh Wani
Giga Sage

Hello @Community Alums 

 

Use this :-

 

data.table = input.table || $sp.getValue("table");
data.sys_id = input.sys_id || $sp.getValue("sys_id");
 

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

 

Regards,

Samaksh

 

Community Alums
Not applicable

@Samaksh Wani still facing same issue.

 

Ankur Bawiskar
Tera Patron
Tera Patron

@Community Alums 

check this link and it has solution

SERVICE PORTAL: RESOLVE INCIDENT BUTTON 

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

Community Alums
Not applicable

@Ankur Bawiskar i have tried with that code too but i was getting same error.