Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Redirect service portal page one to another

dheeru_1994
Tera Contributor

I have a requirement in service portal widget
Below is my client side code 

 

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

    var c = this;
      c.pageredirected = function() {
        c.data.action = true;
      c.server.update().then(function(response){
         if (response.data.ans === true){
          $location.search('id=data_test&eml=asda');
                    // alert('working');
                 }})
        }
};

 

 

 

Here is my server side code 

 

(function() {  
    
        if(input && input.action){
         data.ans=true;  
            //    gs.addInfoMessage('working')
    }
})();

 

 

i have to execute my server side code data.ans= true
then it redirected to the page id which i have given  

1 REPLY 1

Amitoj Wadhera
Kilo Sage

Hi @dheeru_1994 ,

 

Please try the below script it is working perfect in my PDI.

api.controller = function($rootScope, $scope, $location) {
    var c = this;
    c.pageredirected = function() {
        c.data.action = true;
        c.server.update().then(function(response) {
            if (response.data.ans === true) {
                // Instead of modifying the URL query, perform a redirect
                $location.url('/desired/path?id=data_test&eml=asda');
            }
        });
    }
};

 

If you find my response helpful, please consider marking it as the 'Accepted Solution' and giving it a 'Helpful' rating. Your feedback not only supports the community but also encourages me to continue providing valuable assistance.

 

Regards,

Amitoj