- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-04-2018 09:54 AM
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
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-09-2018 06:37 AM
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);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-04-2018 10:02 AM
are you using the OOB form widget to insert these records or something custom? If you are using the OOB form widget, you can put an event listener on the sp.form.record.updated event, but unfortunately, I don't think that event tells you the sys_id of the record or what type of record it is. I had to end up cloning the form widget so I could pass another object into the event broadcast that told me what table and sys_id was inserted/updated.
Once you are able to determine that, you can use the $location object to redirect on the client side.
If you can give me more details about your use case and which widget you are using (custom or form widget), I may be able to narrow down that response.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-07-2018 09:50 AM
Hi Jon,
Thank you for your response!
We are building a custom widget that inserts catalog items. We would like to redirect the user to another form when the catalog item has been inserted. I have added the basic of how we are creating the catalog item and storing the sys_id in the data.sys_id object. I'm not sure if there is a way to check if the data.sys_id variable has been updated from the client side to preform the redirect.
//Server Side Code
var cat = new GlideRecord('sc_cat_item');
cat.intialize();
cat.name = input.name;
cat.u_vendor_part_number = input.vendor_part_number;
cat.price = input.price;
cat.short_description = input.short_description;
cat.description = input.description;
data.sys_id = cat.insert();
Please let me know if I can clarify anything.
Thanks,
Forrest

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-07-2018 03:37 PM
so you can do the redirect in the client controller as opposed to the server script. here is the basic idea of how to do that (you need to include $location in your client controller function parameters):
var srch = $location.search();
srch.id = "your_new_page_id";
srch.sys_id = c.data.sys_id;
$location.search(srch);
Can you post your client controller too? are you doing a server.update() to get to that server function on the click of some button by the user? If I can see your client controller function, I can show you where to put the above code
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-08-2018 02:41 PM
Hi Jon,
Thanks again for your reply!
Here is the basics of my code. I have a save button on the record that calls a saveRecord() function in the controller. The saveRecord() function makes sure all the field variables are updated and then sets the data.save_button_value variable to true to detect the save on the server side. I then make the server.update() call to send the data object back to the server. My catalog item is created successfully. I tired your redirect script and I was able to make it work when the form loads. My issue now is I need to trigger it when the data.sys_id variable is populated. Right now I have a data.sys_id != '' check, but I believe the client script only runs onLoad. Is there an angular function that checks for variable changes at any point?
HTML
<div>
<button id="saveButton" type="button" class="sp_btn btn bg-primary pull-right" ng-click="saveRecord()">Save</button>
</div>
Client
function ($scope, $location, spUtil) {
if ($scope.data.sys_id != ''){
alert ('found sys_id');
var srch = $location.search();
srch.id = "bundle";
srch.sys_id = $scope.data.sys_id;
$location.search(srch);
}
//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);
});
};
}
Server Side
//Insert the new bundle catalog item
if (input.save_button_value == 'true'){
var cat = new GlideRecord('sc_cat_item');
cat.intialize();
cat.name = input.name;
cat.u_vendor_part_number = input.vendor_part_number;
//Price of bundle is the total price
cat.price = input.price;
cat.short_description = input.short_description;
cat.description = input.description;
data.sys_id = cat.insert();
gs.addInfoMessage('Inserted Bundle ' + cat.name);
}
Thanks again for the help!
-Forrest