How do you call a redirect on a Service Portal widget from the server side?

forrestfalk
Giga Contributor

I am trying to call a page redirect from the server side after I insert a record from a service portal widget. I want to pass back the sys_id I get from creating the record on the server side to the client side and redirect the users to the new URL. Right now I am storing the sys_id in the data.sys_id object. I am having issues on calling a client side function or detecting when the data.sys_id variables changes. I'm probably missing something simple, but any help would be appreciated!


Thanks,

Forrest

1 ACCEPTED SOLUTION

Can you move your new “if” block inside the server.update().then Area? That part is what gets called asynchronously after your server script saves the record. I would put it right after spUtil.update($scope);

View solution in original post

6 REPLIES 6

Can you move your new “if” block inside the server.update().then Area? That part is what gets called asynchronously after your server script saves the record. I would put it right after spUtil.update($scope);

forrestfalk
Giga Contributor

Hi Jon!

Thanks for the response! You're recommendation worked perfectly! Know I understand that the .then is the callback function for the server update. 

 

Thanks,

Forrest

 

Client Script

//Save all the data on the bundle
	$scope.saveRecord = function(){
		$scope.data.save_button_value = 'true';
		//Set the input variables
		$scope.data.short_description = $scope.short_description;
		$scope.data.description = $scope.description;
		$scope.data.name = $scope.name;
		$scope.data.vendor_part_number = $scope.vendor_part_number;
		$scope.data.price = $scope.price;
		
		//Send the inputs to the server
		$scope.server.update().then(function(response) { 
        
                   spUtil.update($scope);    
	           //redirect to new bundle
		   var srch = $location.search();
		   srch.id = "bundle";
		   srch.sys_id = $scope.data.sys_id;
		   $location.search(srch);
    });
};