• April 8, 2026
  • Kishore Thutaram
  • 0

Implement a session timeout mechanism that refreshes the session after a period of inactivity

Requirement: If the output session is idle for a specific time without any user intervention, set the timeout and raise a message pop-up to make a forcible refresh.

File: Controller.js

Implement the code below.


onInit: function () {
			
						
	var osetTime;
	var oPromise = new Promise(function (res, rej) {
	this.getOwnerComponent().getModel().read("/TIMESet", {
	//if we define the time at backend dynamically	
                  success: function (data) {
			osetTime = data.results[0].Time * 1000;
			res();
					},
			error: function (err) {
			osetTime = "300000";
			rej();
					}
				});
			}.bind(this));

			oPromise.then(function (val) {
				var timer;

	function timeOut() {
	clearTimeout(timer);
	timer = setTimeout(function () {
		MessageBox.show(
			"Click OK to Refresh", {
					icon: MessageBox.Icon.Error,
					title: "Session Timeout",
					onClose: function (sAction) {
									location.reload(); // eslint-disable-line sap-no-location-reload
								}
							}
						);
					}, osetTime);
				}
				document.onmousemove = timeOut;
				
			});
}
   
    

Kishore Thutaram

SAP Solution Architect | 16+ Years' Experience in SAP | Sharing Practical SAP Knowledge | Engineering Graduate with Expertise in SAP Architecture

https://fiowelt.com