The Zurich release has arrived! Interested in new features and functionalities? Click here for more

"top.window.location" not working in onSubmit catalog client script?

patricklatella
Mega Sage

Hi all,

I've got a catalog item with an onSubmit catalog client script that builds a URL, and then when the user submits the form they need to be redirected to that URL.  Did something with "top.window.location" break in New York?  The script is working about half the time, sometimes it correctly directs the user to the URL in the script, and sometimes it ignores that script.  Anyone else seeing this behavior or see an issue with my script?  Thanks!

Here's the script:

function onSubmit() {

var req = g_form.getValue('enter_your_vsa_request_number_to_get_started');//this is a reference field to the [sc_request] table
var URL = "itc?id=sc_request&table=sc_request&sys_id="+req;
alert('You will be directed to the Selected Vendor Assessment Request. Please click OK.');
top.window.onbeforeunload = null;//this removes the popup that asks if you want to leave
top.window.location = URL;
}

1 ACCEPTED SOLUTION

Michael Jones -
Giga Sage

You could try a good, old-fashioned setTimeOut. Move the last part of your code into a separate function and have it call-back after a second or so. 

function onSubmit() {

var req = g_form.getValue('enter_your_vsa_request_number_to_get_started');//this is a reference field to the [sc_request] table
var URL = "itc?id=sc_request&table=sc_request&sys_id="+req;
alert('You will be directed to the Selected Vendor Assessment Request. Please click OK.');

top.window.onbeforeunload = null;//this removes the popup that asks if you want to leave
setTimeout(sendOff(URL), 1000);
}

function sendOff(URL) {
top.window.location = URL;
}

That seems to be working every time for me...

If this was helpful or correct, please be kind and remember to click appropriately!

Michael Jones - Proud member of the CloudPires team!

I hope this helps!
Michael D. Jones
Proud member of the GlideFast Consulting Team!

View solution in original post

15 REPLIES 15

Michael Jones -
Giga Sage

That really is .... incredibly odd. I just sat here for 5 minutes and tested about 50 times and can't seem to replicate your issue. The redirect always seems to work! Are you using Chrome? IE? Edge? I wonder if the browser has any impact...

I hope this helps!
Michael D. Jones
Proud member of the GlideFast Consulting Team!

Right?!  Using Chrome...on NY...what version are you testing on?

patricklatella
Mega Sage

I just did 7 tests in row, worked first 5, then next one didn't work, then next one worked.  Must be something buggy in our system?

I have tried now about 200 times. I tried in both a New York instance and a Madrid instance and - every time - it's working. I have to admit, I'm baffled!

I hope this helps!
Michael D. Jones
Proud member of the GlideFast Consulting Team!

thanks Michael for your help...I'm going to continue to troubleshoot but I'm now thinking the issue may have something to do with a business rule I am also running that is taking the RITM that is being created through this catalog item and setting its "Request" field to the REQ that is selected on the form (that you see there in the script, the "var = req").  This is for a business need, but I'm thinking a different approach may be necessary.  thanks again!