Tuesday, April 01, 2008

What is a WEBLIB?

I recently posted about IScripts, and in that post, I mentioned the term WEBLIB. The next logical question after "What is an IScript" is, "What is a WEBLIB?" Simply put, a WEBLIB is a container for an IScript. The term WEBLIB has a history somewhat like the Menu definition. It is a legacy artifact that really isn't necessary but continues to exist because we implemented it that way in the beginning, when the way we implemented it was the most logical way to implement it (before Application Packages, etc). A WEBLIB is similar to a FUNCLIB. The only difference between a WEBLIB and a FUNCLIB is the name... and the way PeopleSoft treats the code within the record defintion. Just like a FUNCLIB, something you studied in PeopleCode class, a WEBLIB is a Derived/Work record definition with a special name. When you prefix a record with WEBLIB_, you are telling the PeopleSoft application code to allow people to access the functions defined within that record. Just like any other record defined function, functions defined in records prefixed with WEBLIB_ can be declared and called from any PeopleCode. What makes WEBLIB_ functions unique is that they can also be called from a URL (see my previous post on IScripts). Therefore, the term WEBLIB describes the type of record used to store a special type of PeopleCode function, an IScript.

Because WEBLIB's can be accessed from a browser using a specially formed URL, we need to secure them. Just like standard components, you define WEBLIB security on permission lists. When you open a permission list, you will notice a link across the bottom titled Web Libraries. From this tab, you can specify which WEBLIB functions a permission list (and, indirectly, a user) can access. This is where the magic of the record name prefix appears: only records prefixed with WEBLIB_ can be added to the Web Libraries section of the permission list.

One of the frustrations of the WEBLIB design is the record name requirement. Generally speaking, a PeopleSoft implementation will involve custom record development. An implementation team usually prefixes these custom record names with a company or team abbreviation. This helps the team distinguish custom tables from delivered tables. Because WEBLIB's must start with the prefix WEBLIB_, this is not possible. Instead, the implementation, or development, team is required to move the team specific prefix to the next component of the record name, the part following the WEBLIB_. Now, if the team prefix is 3 characters long including an _ (for example, ADS_), then the developer only has 4 characters left to uniquely and accurately describe this WEBLIB's purpose. Why? Because a record definition can only contain 15 characters and the first 11 are used by system and team required prefixes.

To demonstrate, let's look at a delivered WEBLIB, WEBLIB_QUERY. WEBLIB_QUERY is a Dervied/Work record that you can open in Application Designer. When you open this record, you will notice that it contains 3 fields with PeopleCode. The first 2 fields contain IScript functions, and the 3rd, QRYGENFUNCS, contains FUNCLIB, not ISCRIPT, functions. The difference between the functions in the 3 fields has to do with the function prefix, not the field names. To make a PeopleCode function available from a URL, the function not only has to be contained in a record definition prefixed with WEBLIB_, the specific function name must also be prefixed with IScript_. To see an example of WEBLIB permissions, open the Permission List PTPT100 and switch to the Web Libraries tab. From here, you can see WEBLIB_QUERY and the 2 IScripts contained within that WEBLIB.

16 comments:

Chakravarthy Ithayamani said...
This comment has been removed by the author.
Pon Arun Kumar said...

Hi Jim,

Hope you are doing great !

I am a frequent visitor for your blog for almost more than a year now,.. and this is the first time I am scrapping you.

My question:

I am looking for exporting the content reference - URL of a particular page from within peoplesoft or if feasible a group of url's of the pages under a folder in peoplesoft. Is this feasible by using WEBLIB_CREF ?

Any thoughts on this regard would be higly appreciated.

Jim Marion said...

@Pon Arun Kumar, Are you trying to get the URL for a component? If so, try GenerateComponentXXXURL. If you want the full URL for a particular page, then look at the JavaScript variable strCurrUrl. If you have Firefox with Firebug, if you are in a PeopleSoft component, and if your URL has psp in it, go to the Firebug console and type

frames['TargetContent'].strCurrUrl

This will display the URL for the current component.

If you want to get the CREF name for a URL, then submit that URL to an IScript/WEBLIB and use the PortalRegistry.FindCRefForURL method to get a reference to the CREF.

Somehow, I don't think I've answered your question. Yes, you can do what you are trying to do from a WEBLIB/IScript. Reading your question again... Let me rephrase with an example:

Let's say that a user has access to the PeopleTools > Security > Permissions & Roles folder. Let's also say you want to generate a page with links to the items in that folder (for display in an Ajax popup, etc). Can you enumerate the URL's for the items in that folder? Yes. First you need a reference to the folder you want to enumerate. Look up FindFolderByName in the PeopleCode API Reference PeopleBook for an example. If you don't know the CREF name for folder, you can "walk" the hierarchy starting from the PortalRegistry.RootFolder property. Once you have a reference to the folder, you can enumerate the CREF's by accessing the folder's ContentRefs collection. Each of the CREF's in the ContentRefs collection has multiple URL properties, like AbsolutePortalURL, etc.

Pon Arun Kumar said...

Great!

I was looking out for "AbsolutePortalURL". I quickly ran through the peoplecode API reference peoplebook and got an idea.
In the meantime,..
Say for example, I have the portal object Name "XXXXXXXX_GBL", component details , etc from the PORTAL_CREF_ADM page, Is there any way in which i could export the result of the "Test Content Reference" into a flat file ?

So that I am reading from the flatfile and displaying it on a popup or any other window outside peoplesoft environment ? The whole idea is to provide a non-peoplesoft user to get into the exact place within peoplesoft. so that the complexities of navigation is avoided.

Pon Arun Kumar said...

By exporting the result of the "Test Content Reference" into a flat file ?

we are able to retrieve the complete URL right? All I am trying to do is to capture this information (complete URL) into a flat file.

Jim Marion said...

@Pon Arun Kumar, yes, you can export the contents to a flat file. Use the GetFile function with a File object to write the AbsolutePortalURL and label to a flat file. If you want to do this as a batch process, then I suggest an AppEngine scheduled to run daily. Using a File object, you can create the entire HTML index.

Here is another idea... Are you displaying a list of links on another site? Then try this, create an IScript that returns JSON in the format [{url: "http://...", label: "The link title"}, ...]. Give guest access to the IScript. On your other site, use Ajax to read the JSON and display the list.

If you prefer something a little more static, then, yes, go with the File object.

Pon Arun Kumar said...

Hi Jim, I tried browsing the peoplebooks for sample iScripts returning JSON.. Could you please post a sample? It would be of great help.
Thanks,

Jim Marion said...

@Pon Arun Kumar, PeopleBooks does not have examples of IScripts returning JSON. Since JSON is just text, you can use %Response.Write to write your JSON text just like you would write HTML. I will work on an example to post as a new blog entry. Thank you for the excellent suggestion!

Jim Marion said...

@Pon Arun Kumar, I added a JSON example post: Serve JSON from PeopleSoft.

Pon Arun Kumar said...

Thanks a lot for the posting Jim, I have started reading it.. will let you know as of how it works for me :-)

Thanks

Satyen said...

Jim,
Great blog and very informative.
I am looking to access the strCurrUrl js variable in PeopleCode, into a PC variable. Or is there a Peoplecode Global Valiable that has this value? I tried using AbsolutecontentURL property. I was unable to use it because I could not capture the cref using the GetCrefXXX functions dynamically.
Can you share a code snippet to get the URL in strCurrUrl or the absolute content url into a PeopleCode Variable?
Thanks
Bose

Jim Marion said...

@Satyen, strCurrUrl is a client side variable. On the server side, if the URL is a component URL, then you should get the same values from the %Request variable's properties. The PeopleBooks documentation for RequestURI shows how to reconstruct a URL (server, path, query string, etc).

If the delivered method doesn't satisfy your needs, then I would add an HTML Area to the page with JavaScript and HTML to copy strCurrUrl to a custom input type="hidden" form field. When the form is posted to the component processor, the value of the form field will be available to the %Request.GetParameter() method. Just make sure you name your hidden input field with a cryptic name that is not likely to match an existing field name.

Shawn Twenter said...

Hi Jim,

enjoyed your sessions at Alliance this year.

I want to supply user with link to WEBLIB_ IScript_ method as and external link for say a mobile page.

after they log in the url has a ?&cmd=login&languageCd=ENG appended. Which doesn't execute the iscript...? just gives me a blank page. do you know a work around this?

Thanks

Jim Marion said...

@Shawn, I am very glad you enjoyed the session at Alliance this year. It is one of my favorite conferences each year.

I wanted to test out what you stated in your question. When I navigate to a URL that looks like this: http://my.peoplesoft.server/psc/portal/EMPLOYEE/EMPL/s/WEBLIB_THE_ISCRIPT.ISCRIPT1.FieldFormula.IScript_MyFunction and I have not logged in, then I do see a login page, which is what we would all expect. After logging in, it takes me directly to the iScript. It did not add ?cmd=login. I have seen various tools releases treat this differently, so that could be the problem. The other thing I suggest you review is the signon.html template in your sites psftdocs directory in the WEB-INF folder of the web server. Perhaps it has the signon target hard coded?

Shawn Twenter said...

Hi Jim and thanks for the response,

We are on PT 8.50 and it is in the script on the signin.html page, i believe this is delivered code.

Thanks,
Shawn

Jim Marion said...

@Shawn, the way it works on my system is that I hit the iScript URL and the system returns a login page for that same URL. When I submit my credentials, the login form's action appends the ?cmd=login&languageCd=ENG to the form post. PeopleSoft processes this form post, and then just returns the iScript contents itself without the ?cmd=login... it sounds like you are seeing different behavior. If that is the case, then I have two recommendations for further assistance:

1. Log a case with support
2. Submit a question to the PeopleSoft General OTN forum