How do I make a "Widget" with a "Button" in the Portal, redirect the user to the homepage

F_bio Santos
Kilo Sage

Im trying to redirect the user to the portal homepage when he click's the button that is on this widget:
(I tried some thinks but it never seems to work ...)

HTML:

 

<div class="panel panel-default">
 <div class="panel-heading">Actions</div>
 <div class="panel-body">
 <button type="button" class="btn btn-primary btn-block" ng-show ="data.state == '2'" ng-click="c.uiAction('resolve')">Resolve</button>
 <button type="button" class="btn btn-default btn-block" ng-show ="data.state == '1'" ng-click="c.uiAction('assign_to_me')">Assign to Me</button>
 </div>
</div>

 


Server Script:

 

(function() {

    // Get table & sys_id
    data.table = $sp.getParameter("table");
    data.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;

    data.state = gr.getValue('state');
    if (input && input.action) {
        var action = input.action;

        // If Incident table
        if (action == 'resolve') {
            // Resolve Incident
            gr.setValue('resolved', true);
            gr.setValue('state', 8);
            gr.update();
        }
        if (action == 'assign_to_me') {
            gr.setValue('assigned_to', gs.getUserID());
            gr.update();
        }
    }

})();

 


Client Controller:

 

api.controller = function() {
    var c = this;
    c.action = function(state) {
        c.data.state = state;
    };
	
var hosturl = 'https://' + $window.location.host;
$window.location.href = hosturl + "/sp?id=sc_home";

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

 

 

1 ACCEPTED SOLUTION

Tushar
Kilo Sage
Kilo Sage

Hi @F_bio Santos 

 

Can you please try with below script - 

 

HTML -

 

<div class="panel panel-default">
    <div class="panel-heading">Actions</div>
    <div class="panel-body">
        <button type="button" class="btn btn-primary btn-block" ng-show="data.state == '2'" ng-click="c.uiAction('resolve')">Resolve</button>
        <button type="button" class="btn btn-default btn-block" ng-show="data.state == '1'" ng-click="c.uiAction('assign_to_me')">Assign to Me</button>
    </div>
</div>

 

Client Controller -

 

api.controller = function($window) {
    var c = this;
    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 + "/sp?id=sc_home";
        });
    };
};

 

Please, don't forget to mark my answer as correct if it solves your issue or mark it as helpful if it is relevant for you!

Regards,
Tushar

View solution in original post

1 REPLY 1

Tushar
Kilo Sage
Kilo Sage

Hi @F_bio Santos 

 

Can you please try with below script - 

 

HTML -

 

<div class="panel panel-default">
    <div class="panel-heading">Actions</div>
    <div class="panel-body">
        <button type="button" class="btn btn-primary btn-block" ng-show="data.state == '2'" ng-click="c.uiAction('resolve')">Resolve</button>
        <button type="button" class="btn btn-default btn-block" ng-show="data.state == '1'" ng-click="c.uiAction('assign_to_me')">Assign to Me</button>
    </div>
</div>

 

Client Controller -

 

api.controller = function($window) {
    var c = this;
    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 + "/sp?id=sc_home";
        });
    };
};

 

Please, don't forget to mark my answer as correct if it solves your issue or mark it as helpful if it is relevant for you!

Regards,
Tushar