UI Action Javascript Errors With client-side AND server-side code

Chris Sanford1
Kilo Guru

I've recently discovered several browser errors saying "'current' is not defined" in my chrome browser console. It looks like the cause is UI actions that contain both a client-side function and a server-side function. They use the gsftsubmit function which I think I have seen before on SNGuru and in the community. Although the code works fine, it results in a browser error since 'client' is checked on the UI action.

The reason this has become such an issue now is because I am trying to use automated test framework for the first time, where the test will fail if any client-side javascript errors are encountered. Has anyone else experienced this issue, or found a way around it? Are UI actions with client and server side code just bad practice?

1 ACCEPTED SOLUTION

kelseyneis
Giga Contributor

The server side code causes an error when it's run as client side code. I ran into this same issue, and fixed it by wrapping the server code in a function. 

runClientCode(){
//client side code
}

if(typeof window == 'undefined'){
     runServerSideCode()
}

function runServerSideCode(){
     current.update();
     action.setRedirectURL(current);
}

View solution in original post

3 REPLIES 3

Chris Sanford1
Kilo Guru

Update: I moved the server-side code to a separate UI action and unchecked 'client' on that one, and just call the server-side one from the client-side one using gsftsubmit(). It seems to be working well.

kelseyneis
Giga Contributor

The server side code causes an error when it's run as client side code. I ran into this same issue, and fixed it by wrapping the server code in a function. 

runClientCode(){
//client side code
}

if(typeof window == 'undefined'){
     runServerSideCode()
}

function runServerSideCode(){
     current.update();
     action.setRedirectURL(current);
}

Sorry for late reply, but I was experiencing this again and this solution works! Thanks.