SpModal opens up twice again after submitting a request.

zeist_
Tera Expert

Hi All, 
I am working on a Record Producer and it has a SpModal popup which has a simple function, if the user selects "Yes" it will take in the values the user has entered. If he clicks "No", it will clear out the fields.
It is working as expected but when I submit the form and then open it again to submit another request, the SpModal opens up 2 windows one according to the latest message and one with the older request.
Can you please help me out with this ?

Here is my Client Side Script:

api.controller = function($scope, $rootScope, spModal) {

    var c = this;
    $scope.page.g_form.setVisible("Note", false);
    $scope.msg = '';
    $scope.onLoad = function() {
        c.server.update().then(function(res) {
            $rootScope.$on("field.change", function(evt, parms) {
                if (parms.field.name == 'u_service')  //onChange condition for business_service
                {	
                    if ($scope.page.g_form.getValue('business_service') != '') {
                        $scope.CheckCat();
                    }
                }
            });
        });
        $scope.CheckCat = function() {
            c.server.get({
                action: 'check_cat',
                category_sys_id: $scope.page.g_form.getValue('business_service')
            }).then(function(response) {
                var submit = response.data.Submit;
                var msg = response.data.HTMLmsg;
                var service = $scope.page.g_form.getDisplayValue('u_service'); //To get the value of "Service" and "Category"
                var category = $scope.page.g_form.getDisplayValue('business_service');
                if (submit == 'false') {
                    $scope.msg = response.data.HTMLmsg;
                    $scope.page.g_form.setLabelOf('Note', msg);
                    $scope.page.g_form.setVisible("Note", true);
                    $('button[name="submit"]').attr("disabled", true); //To  disable the submit button
                } else {
                    var message2 = "You are raising a ticket on " + "<b>" + category + "</b>" + " for " + "<b>" + service + "</b>" + ". If it is Correct, Click on " + "<b>Yes</b>" + " to confirm else click on " + "<b>No</b>" + " to scroll the list again "; // For the default message
                    $scope.msg = response.data.HTMLmsg;
                    if ($scope.msg != "." || $scope.msg != "") {
                        $scope.page.g_form.setLabelOf('Note', msg);
                        $scope.page.g_form.setVisible("Note", true);
                    } else {
                        $scope.page.g_form.setVisible("Note", false);
                    }
                    spModal.open({
                        title: 'Do you agree?',
                        message: message2,
                        buttons: [{
                                label: '✘ ${No}',
                                cancel: true
                            },
                            {
                                label: '✔ ${Yes}',
                                primary: true
                            }
                        ]
                    }).then(function() {
                        $scope.page.g_form.getValue('u_service');
                        $scope.page.g_form.getValue('business_service');
                    }, function() {
                        $scope.page.g_form.setValue('business_service', '');
                        $scope.page.g_form.setValue('u_service', '');
                        $scope.page.g_form.setValue('short_description', '');
                        $scope.page.g_form.setValue('description', '');
                    });
                    $('button[name="submit"]').attr("disabled", false);   //To  enable the submit button  
                }

            });
        };
    };
};

 
I have searched the community a lot related to anything with this but could not find much.
Any help would be much appreciated.
Thank you!

1 ACCEPTED SOLUTION

Hi @Ankur Bawiskar,
I found the solution in a post .

zeist__0-1700035171403.png

I just added $uibModalStack.dismissAll(); before opening my SpModal and it resolved my issue.
Thank you so much for the help.
@Ankur Bawiskar  and  @JonathanJacob 

View solution in original post

6 REPLIES 6

Hi @Ankur Bawiskar,
I found the solution in a post .

zeist__0-1700035171403.png

I just added $uibModalStack.dismissAll(); before opening my SpModal and it resolved my issue.
Thank you so much for the help.
@Ankur Bawiskar  and  @JonathanJacob 

@zeist_ 

Glad to know.

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