Wednesday, June 26, 2013

Using PeopleCode Modals: openPageletActionPageInModal (PeopleTools 8.53)

While typing something in the Chrome JavaScript console, I managed to bring up the function openPageletActionPageInModal. Hmmm, sounds interesting. I drilled to the implementation and saw that you call it like this:

openPageletActionPageInModal("http://your.server.name/psp/ps/EMPLOYEE/HRMS/c/ROLE_EMPLOYEE.HR_EE_PERS_INFO.GBL?")

What does it do? It converts the /psp/ part of the URL to /psc/ and opens the URL in a modal dialog. For me it worked great as long as I followed two simple rules:

  • Included a question mark in the URL. If the URL has no query string parameters, just include a trailing "?".
  • Used this function in the same datababase/application as the content. In other words, I didn't try to use this technique in Interaction Hub for HRMS content. For that to work, I would need to translate more than just /psp/. I would also have to translate the server name and site name.

Note: It works just fine in a portal/content provider situation if the URL is already a /psc/ URL.

Anyway, interesting, undocumented piece of JavaScript that you may or may not find useful. As always, your mileage may vary.

Note: I was using PeopleTools 8.53 when I found this function.

53 comments:

Unknown said...

I am afraid it is not working with me while applying your first rule If the URL has no query string parameters, just include a trailing "?". as will it affect the API in the end ?

Jim Marion said...

I forgot to mention that I found this in PeopleTools 8.53. Are you testing this on PeopleTools 8.53?

Jim Marion said...

I will update the post to note that I am using PeopleTools 8.53.

Unknown said...

Hello! We have a problem in our application. We are upgrading to PT8.53

I am not a developer but trying to help figure out our issue.

We are using "psp" but sometimes it changes to "psc" (when we expect it consistently stay on "psp"). What could possibly cause this to happen?

Jim Marion said...

@Lally, that is interesting. It should not do that. Is this when you click the New Window link or is there any specific pattern? Does it happen when you are using menus to navigate? Are you using Interaction Hub with remote unified nav? This sounds like something that will require a case with Global Support. You may also want to ask your question in the PeopleSoft OTN General Discussion forum.

Tom Mannanchery said...

Hi Jim,

Is it possible to have a link in a pagelet in Interaction Hub, which when clicked opens a modal window with content from 'Managed Content' in it?

Thanks,
Tom M.

Jim Marion said...

@Tom, yes. The way you reference it depends on the content type. If it is something like a news publication, then you can access it through the /psc/ (or even /psp/) URL. Some content, such as non-web content, may use the various "View" PeopleCode functions. You may not be able to view that type of content in a dialog.

Tom Mannanchery said...

Thanks so much Jim. Can such a pagelet be created using the Pagelet Wizard or would it have to be a component-based pagelet?

Jim Marion said...

@Tom, Pagelet Wizard Free Text or HTML (with view source) should work fine. If you are going to use the openPageletActionPageInModal function, the JavaScript should already be available in the portal. An alternative that I prefer is to use jQuery UI's dialog widget.

Tom Mannanchery said...

Hi Jim,

Your suggestion worked. Thanks a lot. Sharing the code from the free text pagelet.


var a = document.getElementById("mylink");
a.onclick = function() {
openPageletActionPageInModal("/psc/pa91dev/EMPLOYEE/EMPL/c/EPPCM_CONTENT_MGMT.EPPCM_PUB_VIEWER.GBL?EPPCM_CONTENTID=2509&SHOW_SUMMARY=Y");
};


Open Content in Modal Window

Thanks,
Tom

Jim Marion said...

@Tom, thank you for sharing. Do you need to return "false" from your onclick function to cancel the default action?

Tom Mannanchery said...

That's a neat observation Jim. The href value is #, so I am assuming the return false is not needed. Do you think it could cause any issues?

Jim Marion said...

@Tom, I recommend returning false to cancel the default event. Otherwise, it will navigate somewhere else. That "somewhere else" just happens to be the current page. You should notice this in the URL because the URL will now have a "#". You may not notice a difference. It might work fine. It is just one of those things that may come up later to cause unexpected behavior. If possible, I like to deal with those ahead of time. I find that if I ignore things like this, then if they do cause problems, I have completely forgotten what caused them.

Tom Mannanchery said...

Thanks again Jim. I will surely make that change so that I don't have to bang my head later.

Tom

Jim Marion said...

@Tom, Exactly! :)

Tom Mannanchery said...

Hi Jim,

In the code that I posted, I have included the URL to the component that I want to open in the modal window. You may notice that its a relative URL, but the site name is 'pa91dev'. This will break when we migrate this to another env as the site name there could be pa91tst.

I was researching for a few alternatives and came across your blog post for custom transformers. Do you think that approach would be best in this case?

Thanks,
Tom

Abhay said...

i am working on 8.52. can i use this.
i have tried to populate the page in light box use below code. but not able to close it by clicking any value in the grid field(hyperlink)... can you please help me on this.

Jim Marion said...

@Tom, I absolutely, without a doubt, believe that the custom DisplayFormat is the best way to implement what you require. That is how I have it implemented. My book contains a chapter showing a custom Meta-HTML processor. I use that as the base for doing the string sequence substitutions. The DisplayFormat is very similar to the chapter on creating a custom data type.

Jim Marion said...

@Abhay, when you say, "not able to close by clicking any value in the grid," what do you mean? What happens when you click a value? Do you get an error? Also, you mention that you use lightbox with "below code," but I don't see any code below. Did you post something else?

Tom Mannanchery said...

Thanks Jim. I will go ahead with this approach and let you know how that goes.

Tom

Abhay said...

Actually i'm trying to open a page in a model window. The page is like a prompt page in peoplesoft where you search & select some value and it comes back to the parent page. i managed to open it in model window by using CSS and Iframe & javescript.

but problem is not able pass any field value (that i selected in the model window) from the model page to the calling page. in short my aim is need to create a search custom search page that should work like how prompts work is peoplesoft.

Jim Marion said...

@Abhay, you just made me realize that I incorrectly titled this post. A better title would be "Using PeopleTools JavaScript Modals: openPageletActionPageInModal..."

If you want to use response values in PeopleCode (update the component buffer) then you should choose one of the PeopleCode modal functions, such as DoModal. If you want to return values to your JavaScript, then take a look at the showModalDialog JavaScript function.

Unknown said...

Hello Jim,
I am an ardent follower of your blogs and almost 100% of times your tricks and your suggestions have helped me grow as a PS Developer.
We are in middle if a PeopleTools Upgrade to 8.53 with HR on 9.0 and Portal on 9.1. We are opening HR Pages via Portal and there is this specific transaction of Editing Home and Mail Address that allows Change Country and when we select a new Country the whole branding is lost and we get a JavaScript Error of Expected ')' at PT_AJAX_MIN.JS It points to PAndA(Eval which is a function in ScriptProxy.js which we don't know why it is loading to only this page on Change Country. Because of this the page becomes unusable and we cannot save or cancel and it hangs.
Any suggestions would do wonders.
Please note that this works fine in HR 8.49 and Portal 8.52 where Prompts were on Top of Page Content.
Thanks
Pradeep

Jim Marion said...

@Pradeep, very interesting. I suggest you log a ticket in My Oracle Support. This sounds quite unusual. Perhaps a resource (HTML definition) did not load properly during the upgrade?

Unknown said...

Thanks Jim for your response. Have raised a case but yet to hear from them

Julie said...

Hi Jim, I work for a company that has PeopleSoft CRM. We are implementing 9.1 this weekend. We did not implement the multiple attachment feature which became available in PeopleTools 8.53. I have been trying to research how this would function. I want to actually see the screen the customer sees to browse for the attachments. Do you have suggestions of where I can see this? Thanks

Jim Marion said...

@Julie, are you looking for a delivered page that uses this new feature? I'm not familiar enough with application specific functionality to know. If I were attempting the same thing, I would probably just create a test page in my dev environment and implement the multiple attachment functionality.

Unknown said...

Was wondering if you could offer some advice. My company is using peoplesoft portal with tools version 8.53. We are trying to get a navcollection to open its links in a modal set up. I have a javascript working in chrome and FF but IE is not cooperating at all I am using the openPageletActionPageInModal code you mentioned at the top of the page to accomplish this in a script that sits outside of the pagelet itself and only fires after the pagelet is loaded. Do you have any advice on a probable fix. I have been experimenting with trying to rewrite the xslt that drives the page to apply the openPageletActionPageInModal code to the links that is contains but am not having much luck there either. Any advise would be very much appreciated.

Jim Marion said...

@John, open the IE developer tools window and see if an error appears in the JavaScript console. This is a good way to figure out what is causing the problem in IE.

Unknown said...

Thanks I tried that but it doesn't throw an error. For a bit of a further explanation of the overal problem the script was originally working but we were still getting either new tabs opened up or the current window taken over due to the settings on the links the pagelet. My attempts at removing those target tags did not have any affect towards making it work. In the end I reworked the xsl to not build out the hrefs for the links and keep the links housed in the script itself(did not want to do that this way but was all I could do to get it to work). Now the scripts works as expected in Chrome and FF but IE just continually reloads the home page when the links are clicked instead of opening the modal window. So at this point I am running out of ideas.

Jim Marion said...

@John, do you have an href attribute with no value or "#" for a value? If so the browser interprets that to mean, "reload the page." If you have an onclick handler, are you canceling the event? Browsers (and versions) have different methods for canceling events. Make sure you do that correctly. To ensure that your event handler is called, put something like console.log('onclick') in your JavaScript event handler. Or, since the console will clear when the page reloads, use alert('onclick') instead.

Jim Marion said...

@John, also, don't use document.write in your pagelets. That will cause the homepage to reload.

Unknown said...

Good afternoon have a question for you. I have developed a javascript that uses the modal code you mentioned quite well but it has a slight draw back in that I have to make a code push to our production set up everytime a new link is added to the home page that we wish to use it on. What I am asking is do you have any pointers on how to turn the script from a javascript to an iscript inside of Peoplesoft itself?

Jim Marion said...

@John, how are you adding links to the homepage? I assume it is through Pagelets or Navigation collections? What code do you have to update each time you add a new link to the homepage? The way I handle this is through JavaScript in the pagelet itself. For example, if I have a navigation collection, I will publish it through Pagelet Wizard and use a custom stylesheet. That stylesheet applies a CSS class to every link that is supposed to open in a dialog. I usually use the lack of Replace Window or New Window flags to determine if a link should open in a dialog. I use the onload event (jQuery's $(document).ready is really handy for this) to apply the openPageletActionPageInModal behavior to links.

Unknown said...

The links are added in a couple of pagelets yes. The script that does everything is sitting on the parent page that has the pagelets on it(because we were wanting to be able o attach it to multiple links possibly in different pagelets on a given page). I built it using the dojo libraries to look for the links by there id then once they are found and loaded it applies the openPageletActionPageInModal functionality to the link on click of the link. The problem is if I add a new link to a pagelet that I want to apply this to I have to edit both the pagelet's custom xslt to manipulate the link how I need it to be made to avoid issues that are occurring in IE8+(where even without the take over current window or new tab options enabled It was still acting as if they were). I then also have to edit the javascript code on the parent page to look for the new link to add itself to.

Jim Marion said...

@John, instead of identifying links by ID, can you add a data- attribute or a CSS class? This makes your parent code generic.

Unknown said...

Good afternoon Jim have another question for you. I am working to apply the modal script to a link that contains a page built using the pagebuilder iscript to create a page to house a pagelet that is being hosted to out EP portal from our HR system and am hitting a snag. The snag being that the browser it throwing a cross domain error do you have any thoughts to a work around for this?

Jim Marion said...

@John,A couple of things:

1. If the target page for openPageletActionPageInModal is a different application, then the hostname may be different when using /psc/ than it is with /psp/. IF that is the case, then the function won't work as expected.

2. I had trouble following the flow, so I may have misunderstood. The pagelet is in a different application or the target page is in a different application? Did you register the remote pagelet within the current application? That will proxy everything into the same domain.

Unknown said...

Sorry I have a tendency to ramble. The pagelet in question lives in the HR system and was registered using the pagelet wizard as an embed-able pagelet and then the pagelet was then set up in the quick links we've set up using a cref that is pointing to it. The quick links is assigned on a dashboard that is also hosted on the HR side of the portal over to the EP portal. This part works fine the dashboard flows from the HR system to the EP system with no problems and if the pagelet is embedded as a whole on the dashboard it also works but if we try linking to it using a quick link the resulting page or modal window throws a Uncaught SecurityError with a description of Blocked a frame with origin "domain A" from accessing a frame with origin "domain B". The frame requesting access set "document.domain" to "mycmsc.com", but the frame being accessed did not. Both must set "document.domain" to the same value to allow access.

Jim Marion said...

@John, OK, perfect. Open your web profile in each system. In the General tab, set the Authentication domain (assuming both peoplesoft instances have the same suffix "mycmsc.com." That should resolve the problem.

Jim Marion said...

@John, restart your web server after making the change.

Unknown said...

Hello again, Have a question if you do not mind. I have reworked my modal script so that when called it looks for any links on the page that have a specific class and adds them to an array to open as modal when they are found. This script works beautifully when called by either a link(through an onclick attribute) or pagelet(ones that have a custom xml that can call it on load of the pagelet) but this can be problematic because the script is often called before everything is on the page and it can miss links that it should grab. I would simply have the script called by each pagelet or link as needed but this option will not work because one or two pagelets that I will need to use the script on are of the HTML data type. A data type which I have found generally does not allow for JavaScript calls to be made within it. The text editor that is used by the system for this data type wipes out the calls every time without fail. I know that changing the pagelet to a free text data type solves the problem here but this is also not a very viable solution because the people that may end up supporting this pagelet in the future may not have the experience with HTML, CSS, and/or JavaScript to support it. So I was wondering if you had any advice on how to get the script to fire on the load of the page as a whole. I have tried window.onload, dojo’s dom.ready, Jquery’s .ready, and the DOMContentLoaded property in javascript but they all end up fireing before all of the content is loaded into the page. I assume this is because the page is loading the bones of the page first which the DOM is then set to ready(allowing the scripts to fire). The content however may or may not be done loading by then because it asynchronously loads the content that should be in the pagelets on the page. The content load seems to start a fraction of a second or more after the bones are either done or at least started (the time delay is so short I can’t nail down exactly when it starts). I can say with certainty that even though the document.readyState is set to complete there are almost always a few pagelets that are still loading content in place after the readyState of the page is done. My current solution is a simple time out of about 3 or 4 seconds to stall out the JavaScript execution until the time has expire (usually the content is loaded by then) but as you can imagine this solution also has a major flaw in that the time to load the page and its content could vary wildly from PC to PC.

Jim Marion said...

@John, everything you said makes sense, and yes, that is how it works. The DOM is "ready" and then the pagelets load using Ajax. It happens asynchronously. I'm not sure if there is a good solution. I suppose you could use get a list of all of the pagelets on the page by searching on class name (using jQuery or querySelectorAll or some other method) and then periodically check them for content. If they all have content, you are good to go? It might also be possible to tap into the JavaScript that actually loads all the pagelets using monkey patching. Not sure though as I haven't tried it before.

Unknown said...

Hi Jim,

can we send an attachment through Generic Templates in PeopleTools > Workflow 9.1/8.51?

Thanks!

Jim Marion said...

@Ur, great question. I have no idea. I suggest you ask your question on the PeopleSoft General Discussion OTN forum.

Tamil Ayurvetham said...

Hello Jim,

We use the openPageletActionPageInModal() javascript function to open a HCM Performance appraisal document on Home page using pagelet. And the Current appraisal pagein turn navigates to PeopleSoft direct report page. In this case, the above mentioned function is working as expected. It doesn't display any message.

Unknown said...

Hi,
I'm able to store js and stylesheet scripts on web server and call them from XSL using the web server relative path. However, it seems creating these as PS Objects and calling them would make much sense.

I've created the JS and CSS objects and modified my XSL to call these using iScript. However, I'm getting errors.

Here's the object call:
src="../s/WEBLIB_PTBR.ISCRIPT1.FieldFormula.IScript_GET_JS?ID=JQUERY_JS" type="text/javascript">
src="../s/WEBLIB_PTBR.ISCRIPT1.FieldFormula.IScript_GET_JS?ID=JQUERY_CYCLE_JS" type="text/javascript">


Error:WEBLIB_PTBR.ISCRIPT1.FieldFormula.IScript_GET_JS?ID=JQUERY_JS:1 Uncaught SyntaxError: Unexpected token <


Any ideas?

Thanks!

Jim Marion said...

Your approach is good. I'm not sure about the paths though. Open your browser's inspector and console tools and confirm that the web server returned a valid response for the paths referenced in the src attribute. I'm suspecting not. You can also view the response, which may give you another clue. Another thing to check is security for the WEBLIB_PTBR iScripts and confirm your user can access them.

Unknown said...

Weblib security works and I tried posting the URL in the browser.

Initially, I did not notice the JS script file changed since I had used the /psp/. When I changed it to psc, I noticed the JS file was now changed to https:///cs/SUCS1P/cache/JQUERY_UI_JS_MIN_114.js

I'm looking at your post on disables26.rssing.com/chan-13911451/all_p2.html where you mention adding the code below.
//specialvariabletostore"our"singlejQueryinstance
if(!window.psjq$){
window.psjq$=window.$=window.jQuery;
}else{
//ignorerecentimportandusetheglobalsingleinstance
window.jQuery=window.$=psjq$;
}

Jim Marion said...

I noticed that you were using relative URLs and knew there was a reason I didn't use relative URLs. I just couldn't remember the reason. The reason is because of the servlet name. You are right, the IScript_GET_JS script should not be run from the /psp/ servlet because that returns the HTML frame. It needs to be run from the /psc/ servlet.

Unknown said...

Have a quick question for you have you had any experience with using this do modal command on a fluid home page? I was thinking about using it to make a kind of pop up tutorial for the fluid implementation we are working on and was wondering if you had done anything like that.

Jim Marion said...

@John, Great question. I have not used it in fluid. Fluid is already using /psc/ URLs, so they don't need to be converted. Now that you have me thinking... I have not used modals in fluid at all. I don't recall seeing them either. I wonder if modals fit the mobile design pattern.

Manju said...

Hi Jim,
we upgrading to 9.2/tools 8.56. When accessing the absence request page the delivered domodalpopup() does not seem to work. The page keeps bufferring and nothing happens. When I minimize the page or reduce the browser page size the popup appears but not actionable. It seems to be working in DEMO but not in out DEV environment. Kindly suggest what could be the cause of such a interesting behavior.

Thank you.
Sanjeevan