Widget: spModal

Community Alums
Not applicable

Hello, im changing the OOTB "HR Standard Ticket Actions" widget.

the requirement is:  when click on cancel case, open a model with a choice input that will come from the server.

For this i created a new widget that will be called inside this one with sp.Open. But when I do this, I have no control of the default buttons, like just make Ok available when a choice is selected.

This behavior let the user to submit the cancel button without select a choice. Anyone has any idea how I can solve this?

For this, I created a new field in the Case table with the options.

 

"HR Standard Ticket Actions" widget" (External widget)

HTML no Changes

Server script change: after line 26:

inserted this line: grCase.u_cancellation_reason = input.cancelled_reason;

 

 

Client controller changes:

in the beggining of the function:

function hrcTicketActions($scope, $http, spUtil, $timeout, spModal, i18n, $window, $uibModal, spContextManager, spAgentChat, snAnalytics) {

    /* widget controller */

    var c = this;

                var shared = {}; 

    $scope.showChatWindow = false;

    $scope.rejectResolutionNote = "";

    $scope.resolutionAction = "accept";

                c.showActionDropDown = true;

 

$scope.cancelCase = function () {

                                c.showActionDropDown = false;

                $http.get(

                                '/api/sn_hr_core/utils/getGlideRecord?sysparm_name=getGlideRecordSecureSetData&sysparm_tableName=sn_hr_core_case&sysparm_query=active=true^stateNOT IN1,3,4,7^parent=' +

                                $scope.data.parentCaseId).then(function (response) {

                                spModal.open({

                                                                buttons:[{

                        label: 'Cancel',

                        primary: false

                    },{

                        label: 'Ok',

                        primary: true

                    }],

                                                                backdrop: 'static',

                                                                shared: shared,

                                                                title: "Cancel case",

                                                                value: c.respond,

                                                                widget: 'cancel_form',

                                                                widgetInput: {}

                                                }).then(function (respond) {

                                                                if ((respond.primary == true) && (shared != " "))  {

                                                                var payload = {};

                                                                payload.name = "My Requests";

                                                                payload.data = {};

                                                                payload.data["Action"] = "Cancel Request";

                                                                payload.data["HR Case"] = $scope.data.recordInfo.number;

                                                                payload.data["HR Service"] = $scope.data.recordInfo.hr_service;

                                                                payload.data["Short Description"] = $scope.data.recordInfo.short_desc;

                                                                snAnalytics.addEvent(payload);

                                                                $scope.data.action = 'cancelCase';

                                                                $scope.data.cancelled_reason = shared.valueSelected;

                                                                $scope.server.update();

                                                                }

                                                                c.showActionDropDown = true;

                                                });

                                });

};

 

 

 

EXTERNAL WIDGET: cancel_form

 

HTML:

<div>

                <form class ="form-horizontal">

      <div>

          <label>

               Please provide a cancellation reason

          </label>

          <sn-choice-list field = 'c.defaultCancellationReason'

                        sn-model= 'c.defaultCancellationReason'

                        sn-options = 'c.cancellationOption'

                        sn-value-field="cancellationValue"

                             sn-text-field="cancellationDisplay"

                        sn-items="c.cancellationChoice"

                        sn-on-change="c.valueSelected(selectedValue)">

          </sn-choice-list>

      </div>

               </form>

</div>

 

SERVER:

 

(function() {

                data.cancellation_reasons = [];

               

                var gr = new GlideRecord('sys_choice');

                gr.addQuery('inactive','false');

                gr.addQuery('element','u_cancellation_reason');

                gr.orderBy('value');

                gr.query();

                var reason = {};

                while(gr.next()){

                                                reason = {};

                                                reason.cancellationValue = gr.getValue('value');

                                                reason.cancellationDisplay = gr.getValue('label');

                                                data.cancellation_reasons.push(reason);

                }             

})();

 

 

Client controller:

api.controller=function() {

  // widget controller -show the button to choose a choice and pass the input to the principal widget

                var c = this;

                var shared = c.widget.options.shared;

                c.cancellation_reason = "";

                c.cancellationChoice = c.data.cancellation_reasons;

                c.cancellationOption = {

                                hideSearch: true,

                };

               

                c.valueSelected = function selection(selectedValue) {

                                return angular.isDefined(selectedValue) ? (shared.valueSelected = selectedValue) : shared.valueSelected;

            

                };

};

right now I'm able to select OK without choose no option.

GabrielLisboa1_0-1687946785893.png

 

 

Thank you

1 REPLY 1

Arunava1
Tera Contributor

This is helpful. Thanks