Tuesday, November 13, 2007

Create Your Own Meta-HTML Elements

One thing that keeps me excited about PeopleSoft is the flexibility of the PeopleTools platform. As I was working on a a custom Pagelet Transform Type, following the details outlined in Rich's blog post Markdow Text Filtering for PeopleSoft, I realized I was actually creating a custom Meta-HTML element. How cool is that? Not only can I extend the PeopleCode language using Java, I can also extend the Meta tag set. Here is the code:

Function ResolveMetaHTML(&html as string) returns string
Local JavaObject &pattern;
Local JavaObject &matcher;
Local String &node_url;

REM ** Resolve %NodePortalURL(NODENAME) tags;
&pattern = GetJavaClass("java.util.regex.Pattern")

&matcher = &pattern.matcher(
CreateJavaObject("java.lang.String", &html));

While &matcher.find()
&html = Substitute(&html, &matcher.group(), &node_url);

This Meta-HTML element replaces %NodePortalURL(NAMEOFNODE) with the Portal URL defined on the portal tab of the node NAMEOFNODE. This can be used to ensure images, scripts, CSS, links, iframes, etc point to the correct server at runtime.

If you want to create your own Meta-HTML elements, I suggest you place the implementation of those elements inside an Application Class. This custom Application Class would be responsible for accessing its HTML definition using GetHtmlText and replacing all instances of custom Meta-HTML elements with your implementation of those Meta-HTML elements. Rather than call GetHtmlText directly, your PeopleCode would use your custom Application Class.

If this works for Meta-HTML, why not custom Meta-SQL?


Jeromy said...

Thanks Jim for a wonderful Blog! Some excellent information listed here.

Jeromy McMahon

Sasank Vemana said...

Jim - It looks like the link on this post has moved.

I am interested in implementing custom meta-html and wondering if you can give me some pointers.

How is the ResolveMetaHTML function getting executed?

Did you include it in a delivered JavaScript Object?


Jim Marion said...

@Sasank, you have to create your own Display Format, which is an App Class. You then register this app class in the Pagelet Wizard metadata repository. I have an example of creating a data type in my book. Creating a display format is very similar.

Sasank Vemana said...

Great! Thanks Jim.

I will give that a try.

Khantozavri said...

Hi, Is there a way to take PT System Variable (e.g. #EmailAddress or %UserDescription) and turn it into meta-html so that they can be exposed to javascript just like meta-html %UserId?

Jim Marion said...

@Khantozavri, using the approach above, anything can become "meta-html" for Pagelet Wizard, but only when used through a transformer as in the manner described here.

Khantozavri said...

@Jim, I'm sure what you have said makes lots of sense to those who are more technical than me. I'm not at that level so if you find this too novice - it is.

Here's my need: I have a live chat tool which works via injecting an html object to peoplesoft via branding objects feature. We are PT 8.54.18. That html object is actually a javascrip that has a function to 'identify' which basically accepts variables to identify currently logged in users.

I have taken a leap of faith and knowing (through experimentation) that basic text has several variables (%UserID, %EmailAddress and %UserDescription among others), I passed them all to that tool and discovered that some worked and others didn't.

Through some reasearch I came accross one possible explanation that %UserId works as it is a meta-html (as well as system variable), while %EmailAddress and %UserDescription are just system variables and not meta-html.

I'm not sure if to what you are refering to as tranformers and Pagelt Wizards is really applicable to my situation here, but my need is very simple: pass on to my tool (live chat widget) %EmailAddress and %UserDescription just like the %UserId, hene my original question: Will the logic / approach above work?

Jim Marion said...

@Khantozavri, I see. It isn't a novice question, just a matter of context. HTML definitions (also JavaScript definitions) are used in many places and many ways. In some of those places, a developer has the opportunity to transform the HTML prior to using it. This blog post is based on that transformation concept. Other use cases, such as branding system options, do not. Branding Objects is just an online way to interact with HTML definitions within App Designer, which means branding objects could be transformed if the HTML is accessed by a developer using a PeopleCode function such as GetHTMLText. It sounds like you are using pure JavaScript, however, with no PeopleCode interaction. Without a way to inject PeopleCode, it is not possible to create your own Meta-HTML as shown here. As an alternative, you can use Ajax and an iScript (or a sync Integration Broker service with a PS_TOKEN cookie) to fetch user information. The iScript will run in the app server with full PeopleCode access and can therefore resolve system variables.