Adding button in widget to change state

Hafsa1
Mega Sage

in the "Ticket Conversations" widget in portal I need to add a button name "Change state". It should change case state to 11.

I have created a UI action "Change state" which will change the state.

I need to call it in widget "Ticket Conversations".

Update widget but it is not changing the status, anyone help?

 

HTML section:

<button type="button" class="btn btn-primary btn-block" ng-click="c.uiAction('respond_requestor')">Respond From Requestor</button>

 

client controller:

 c.action = function(state) {
        c.data.state = state;
    };
     c.uiAction = function(action) {
        c.data.action = action;
        c.server.update().then(function() {
            c.data.action = undefined;

            // Redirect to the Service Portal homepage after the action is completed
            var hosturl = 'https://' + $window.location.host;
            $window.location.href = hosturl + "/csm?id=csm_my_lists&table=sn_customerservice_case&view=csp&sel=all";
        });
    };
2 REPLIES 2

Ravi Gaurav
Giga Sage
Giga Sage

Hi @Hafsa1 

Verify that it correctly updates the state to 11.

current.state = 11; current.update();

 

Update HTML 

<button type="button" class="btn btn-primary btn-block" ng-click="c.uiAction('change_state')">Change State</button>

 

Modify Client Controller

 

c.uiAction = function(action) {
c.data.action = action;
c.server.update().then(function(response) {
c.data.action = undefined;

// Handle successful state update
if (response.data.success) {
alert("State changed successfully!");
// Optionally reload or navigate the page if needed
$window.location.reload();
} else {
alert("Failed to change state. Please try again.");
}
});
};

 

modify Server Side in the Widgets

(function() {
if (input && input.action === 'change_state') {
// Load the current record
var gr = new GlideRecord('sn_customerservice_case');
if (gr.get(input.sys_id)) {
gr.state = 11; // Set the state to 11
gr.update();
data.success = true; // Send success response
} else {
data.success = false; // Handle record not found
}
}
})();

--------------------------------------------------------------------------------------------------------------------------


If you found my response helpful, I would greatly appreciate it if you could mark it as "Accepted Solution" and "Helpful."
Your support not only benefits the community but also encourages me to continue assisting. Thank you so much!

Thanks and Regards
Ravi Gaurav | ServiceNow MVP 2025,2024 | ServiceNow Practice Lead | Solution Architect
CGI
M.Tech in Data Science & AI

ï”— YouTube: https://www.youtube.com/@learnservicenowwithravi
ï”— LinkedIn: https://www.linkedin.com/in/ravi-gaurav-a67542aa/

can we add one condition in button that if the status is 8 then only this button should be visible.

and additional comments should be mandatory once clicked on this button