cancel
Showing results for 
Search instead for 
Did you mean: 

'window' object within Personas events

kammaje_cis
Active Contributor
0 Kudos

Scenario:

I am launching different Personas transactions from a UI5 based home page. From UI5, I am calling various transactions using ~transaction parameter in the URL. This approach works well but has one disadvantage. Whenever I call a new URL(transaction), it takes 3 to 4 seconds to load the entire page/transaction. Calling a transaction using session.callTransaction is much faster. (within a second). So I want to skip loading the entire page.

So my approach is to use URL hash and pass Tcode to Personas environment. Ex: /sap/bc/personas?#IW32.

URL hashes do not cause the page to reload. Then capture the hash value within personas scripting and then to call session.callTransaction.

In the screen load event, I called the below function.

window.onhashchange = function(){ alert('hi'); };

Problem:

I see that above event registration does not work, though it does not give any error. Upon changing the hash, callback function does not get triggered.

I tried entering the above code in the browser console, ( after the entire page loaded.) That worked without any issue.

Question:

Is there a way to do proper event registration for window object within personas events?

Any comments are welcome.

Regards

Krishna

Accepted Solutions (1)

Accepted Solutions (1)

clemens_gantert
Active Participant
0 Kudos

Hello Krishna,

that's an intiguing problem.

Your onhashchange handler is not called because you have to attach it to the outmost window.

From a personas script perspective this is the "parent"-window. So this worked for me when executed as a personas script, e.g. as onLoad or onClick.

parent.onhashchange= function(ev){

  var sTransactionName = ev.newURL.substring(ev.newURL.indexOf("#")+1);

  session.startTransaction(sTransactionName);

  sap.personas.scripting.executeScriptInternal({src: ''}); // this is needed to refresh the screen.

};

The other option avoiding having to register a callback is to call the following from your UI5 page:

<personaswindow>.frame[0].sap.personas.scripting.executeScriptInternal({src: 'session.startTransaction("'+sTransactionName+'");'});

The potential problems with this approach are:

1) Cross scripting issues may occur if your UI5 page and personas are not in the same domain.

2) You have to access the right frame, the one that has the method sap.personas.scripting.executeScriptInternal(), which should be frame[0] from the personas main window.

Best Regards,

Clemens

clemens_gantert
Active Participant
0 Kudos

Hi Krishna,

of course, sap.personas.scripting.executeScriptInternal() works only in the SAP Gui for Html and is not an officially supported API, which means it could change in the future (but I consider it unlikely).

Cheers,

Clemens

kammaje_cis
Active Contributor
0 Kudos

Hi Clemens,

thanks a lot for the valuable information. I am encountering a problem though.

When I run Personas in a browser, I am able to navigate to different transactions by changing the hash. So no issues there. (I used the first approach).

But when I launch it from UI5, I show Personas in an iframe. Upon UI5 events, I change the src of the iframe using something like this.

$('#webguiFrame').prop("src", "/sap/bc/personas?sap-client=200#IK34"); This is resulting in an error in Personas framework code.

It looks like window is null, when lauched from an iframe.

Any suggestions please?

Regards

Krishna

clemens_gantert
Active Participant
0 Kudos

Hi,

the trick is to find the right window and to set the window's document.location.hash property.

This is my script to start the change the hash in the embedded iframe:

var frame = $("#<iframeid>");

frame.context.location.hash="SE11";   //frame is jquery wrapper and frame.context is the frame's document

Cheers,

Clemens

kammaje_cis
Active Contributor
0 Kudos

Thanks Clemens. Your insights have been of great help.

clemens_gantert
Active Participant
0 Kudos

You're very welcome. Was an interesting and fun scenario for me too.

Answers (0)