How to reload the form when server side conditions are met on Server side script on widget

Chaiatnya
Tera Contributor

Hello,

I've a requirement, when user language is not one of the languages for the service portal list, then user language to be set to English and it should reload the portal page.

I've configured to update the user language in server script but stuck how to reload the form (how to call client script from server script to reload the form). Can some one help

1 ACCEPTED SOLUTION

palanikumar
Giga Sage
Giga Sage

Hi,

You can't do browser refresh from Server Script. If you are trying this for a widget then try this

In server script add this line if you need refresh the page (inside the if block where you are changing the language)

data.refresh = 'true';

 

In client script add this line to refresh the browser after if sees the flag

if(c.data.refresh == 'true'){
location.reload();
}

 

Note: If the refresh flag is not handled properly then it could lead to infinite refresh. Make sure your logic is proper.

Thank you,

Palani

Thank you,
Palani

View solution in original post

7 REPLIES 7

shloke04
Kilo Patron

Hi,

Can you share more details on your widget code and a screenshot of your portal page as well?

You can auto refresh a widget using a client controller itself:

 

 

function($scope,spUtil) {
setTimeout(function(){
spUtil.update($scope);
}, 3000);
}

The only catch here is that setTimeout won't work on client controller instead we have to use $timeout or $interval to call the function at regular intervals.

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

palanikumar
Giga Sage
Giga Sage

Hi,

You can't do browser refresh from Server Script. If you are trying this for a widget then try this

In server script add this line if you need refresh the page (inside the if block where you are changing the language)

data.refresh = 'true';

 

In client script add this line to refresh the browser after if sees the flag

if(c.data.refresh == 'true'){
location.reload();
}

 

Note: If the refresh flag is not handled properly then it could lead to infinite refresh. Make sure your logic is proper.

Thank you,

Palani

Thank you,
Palani

Thanks @palanikumar , It is working, however it is going to a loop and refreshing every time, can we restrict in client script after reloading it should not go to loop

Hi,

You should set data.refresh = 'true' only if the language is change. If it is not changed then set data.refresh = 'false'

If you cant implement the above logic in the code for some reason then as a work around we can set the value in current session. This will make sure refresh does not trigger until you closed the browser and login again. You can use the below script in server script

var session = gs.getSession();
var clientData = session.getClientData('languageCheck');
if(clientData != 'true'){
data.refresh = 'true';
session.putClientData('languageCheck', 'true');
}else{
data.refresh = 'false';
}

Thank you,
Palani