Friday, May 6, 2011

Run JavaScript on your PeopleSoft pages conditionally

Here, PeopleCode sets the logic that determines when the JavaScript code will run.

This is not as simple as dropping a HTML Area on your page and setting the script in PeopleCode. This is because the value in the HTML Area field remains and the JavaScript code will keep executing at subsequent page refreshes.

Steps:

Lets have a derived/work record TEST_WRK And field HTMLAREA (TEST_WRK – HTMLAREA).

1. Create a HTML definition as your javascript template. Include all the necessary user-defined javascript functions that you need. Eg Html Definition is TESTJS
<input type="hidden" name="USERJSINJECTION" value=""/>
<script type="text/javascript">
function addLoadEvent(func) {
var oldonload = window.onload;
if (typeof window.onload != 'function') {
window.onload = func;
} else {
window.onload = function() {
oldonload();
func();
}
}
}

function user_function1() {
window.open("","toolbar = no");
}
function user_function2() {
alert('Hello from user javascript');
}

addLoadEvent(function() {
%bind(:1)
});
</script>
 

2. At the scroll level 0 of your PS page, insert a HTML Area control. Assign this to the TEST_WRK.HTMLAREA field.


3. Again at scroll level 0 of your page, insert an editbox and assign this again to TEST_WRK.HTMLAREA. And Set the Following Field Property



a. On the Use tab, check Invisible and Modifiable by JavaScript.


b. On the General tab, set Page Field Name to USERJSINJECTION.


4. Now in PeopleCode, to execute your javascript function.


GetLevel0()(1).TEST_WRK.HTMLAREA.Value = GetHTMLText(HTML.TESTJS, "user_function1()");
 
 
Thanks to http://xtrahot.chili-mango.net/.



5 comments:

UMustTrythis said...

Great Blog. I owe you one.

Saeem said...

Can I have this javascript executed in the mail class of the peoplecode, i.e I want the javascript to be executed when sending a mail and the output of the execution to be displayed on the body part of the email

Pawan Mundhra said...

I am not sure why u need that.. U can create HTML based generic template for your notification..

David PS said...

Hi There:

I am trying to create a HTML pagelet with language versions. I initially created the pagelet in 8 languages but the problem I run into is when I select a different language like esp, there is no way to have the pagelet change to the corresponding language, and I cannot control by security since the user is already logged in. I now created a jquery pagelet to switch the language when the user selects a different language. This works but when the homepage refreshes because of the LANGUAGE selection, THE PAGELET refreshes back to the ENG version. Do you know how I could prevent this or use a component based pagelet to address my issue?

Thanks,
David

Unknown said...


I enjoy most of your articles,the articles are very informative for readers.

Nersha
www.gofastek.com

Post a Comment