3 Replies · Latest reply on May 30, 2017 9:48 AM by Ivan Khimichenko

    Service Portal: redirect after submit callback doesn't work

      hi guys,

      I've a home page like https://devXXXXX.service-now.com/my_portal

      I would like to redirect to this homepage from another page https://devXXXXX.service-now.com/my_portal/?id=customer_profile&sys_id=4251bd71db8e7a008381d79b5e96115d

      after submit form.

      My client script:

      c.updateCustomer = function(){
          c.data.action = 'updateCustomer';
          c.data.sys_id = sys_id;
          
          c.server.update().then(function(){
              document.location = '/my_portal/';
          });
      };
      

       

      But script doesn't redirect me to https://devXXXXX.service-now.com/my_portal  page - it redirects me to https://devXXXXX.service-now.com/x_71311_customers.do?sys_id=770ce606dbba3200b7d0f20ebf961946

      Why?

       

       

      Server script looks like:

      if (input.action == 'updateCustomer') {
          var cust = new GlideRecord('x_71311_customers');
          cust.addQuery('sys_id', input.sys_id);
          cust.query();
          while (cust.next()) {
              cust.active = false;
              cust.update();
          }
      }
      
        • Re: Service Portal: redirect after submit callback doesn't work
          Shahid Shah

          Have to be honest. Just had a quick scan of the question and wanted to point out that you can do redirects with the $window or $location AngularJS components. For example

          $window.location.ref='/portal_name/';
          
          1 of 1 people found this helpful

          *****
          Did I help? Please like, tag helpful or mark it as the correct answer. Thanks!

            • Re: Service Portal: redirect after submit callback doesn't work
              Shahid Shah

              OK. I just tried it for myself and got the redirect working for me. Here's the widget I put together

               

              HTML Template

              <div class="panel panel-primary">
              <!-- your widget template -->
                <div class="panel-body">
                  <div class="form-group">
                    <label for="shortDescription">Short Description</label>
                    <input type="text" class="form-control" id="shortDescription" placeholder="Enter a short description" ng-model="c.data.short_description" />
                  </div>
                  <div class="form-group">
                    <button class="btn btn-primary btn-block" ng-click="c.createIncident()">Create Incident</button>
                  </div>
                </div>
              </div>
              

               

              Client Script

              function($scope, $window) {
                /* widget controller */
                var c = this;
              
                c.createIncident = function() {
                c.server.update().then(function(response) {
                c.data = {};
                $window.location.href = "/sp/";
                });
                }
              }
              

               

              Server Script

              (function() {
                /* populate the 'data' object */
                /* e.g., data.table = $sp.getValue('table'); */
                if (!input)
                return;
              
                var newInc = new GlideRecord("incident");
                newInc.initialize();
                newInc.short_description = input.short_description;
                newInc.insert();
              })();
              

               

              I hope this helps

              1 of 1 people found this helpful

              *****
              Did I help? Please like, tag helpful or mark it as the correct answer. Thanks!