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

Ankur Bawiskar
Tera Patron
Tera Patron

@zeist_ 

you are using widget and including it in custom type variable?

please share some screenshots.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Yes @Ankur Bawiskar , exactly.

I am attaching the screenshot of the custom variable here.

@zeist_ 

are you not closing the modal once user clicks the button?

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@Ankur Bawiskar 
Yes that is the problem, let me show you the portal side.

zeist__0-1700022795627.png


This my SpModal with the message. Now I click Yes and the SpModal closses and I raise the incident. (This is a Record Producer)
Now I go back to a fresh Record with different category, but now I get 2 SpModal popups.
One with the new Value and one with the older Value.
Attaching the screenshot below.

zeist__1-1700023003965.png

After Clicking Yes or No
I get the same old Pop up which I have not even selected:

zeist__2-1700023076139.png