Portal Form Widget: Redirect on Submit/Insert
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-11-2022 08:05 AM
Hi,
I have a Custom Scoped Application with a Portal.
In the Portal I have a custom form, copied from the widget-form (I _think_).
The form may be revisited and information incrementally added, via the Save button.
Once a "form complete" checkbox is ticked, a Submit UI Action button is displayed:
The Submit UI Action sets a couple of values and inserts the form information into my custom scoped table.
// set values
current.field1 = 'value';
current.state = 2;
gs.addInfoMessage('Form Submitted');
// update record
current.update();
What I then want to happen is for the browser to redirect back to my Portal homepage.
I read: Workaround to use action.setRedirectURL in Portal UI action
In ignorance, I hacked the scripts there and modified my widget, as so:
//CLIENT CONTROLLER
loadForm($scope.data.table, sysID).then(constructResponseHandler(response)).then(redirectFix);
function redirectFix(){
ctrl.data.action = "checkRedirect"
ctrl.server.update().then(function(response){
if(response.forceRedirectTo){
$window.location = (response.forceRedirectTo);
} else {
ctrl.data.action = ""
}
})
}
// SERVER SIDE SCRIPT
if(input.action === "checkRedirect"){
data.forceRedirectTo = 'https://www.google.com';
return;
}
As you likely realise this results in a redirect on click of both the Save AND Submit button.
I'm looking for some assistance as to the best way to implement this redirect, following the click of the Submit button.
As you can see I don't know any AngularJS 😞
R,matt
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-16-2022 02:44 AM
For anyone interested I think I got the answer:
[Client Script]
...
// inside this
$scope.triggerUIAction = function (action) {
//...
// I added this - my action.action_name for Submit btn == 'Submit Appeal'
ctrl.data.my_action_name = action.action_name;
//...
// inside this
$scope.$on("spModel.uiActionComplete", function (evt, response) {
//...
// I added this
// [OLD LINE] loadForm($scope.data.table, sysID).then(constructResponseHandler(response));
loadForm($scope.data.table, sysID).then(constructResponseHandler(response)).then(redirectFix);
// at the bottom, still inside top function, I added this
function redirectFix() {
// suspect set here allows use of value in server script
ctrl.data.action = "checkRedirect"
ctrl.server.update().then(function (response) {
if (response.forceRedirectTo) {
$window.location = (response.forceRedirectTo);
} else {
ctrl.data.action = ""
}
})
}
[Server Script]
// at the end I added
if (input.action === "checkRedirect" && input.my_action_name == 'Submit Appeal') {
var instance = gs.getProperty('glide.servlet.uri');
var suffix = '<PORTAL HOMEPAGE>';
var url = instance + suffix;
data.forceRedirectTo = url;
return;
}
Seems to work.
Any improvements gratefully accepted.
atb,matt
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-29-2024 08:39 AM
It gives an error on the Server Script If condition.
Cannot read property "action" from undefined