Thursday, January 31, 2008

%Component Gotcha

I was just writing an IScript for the Approval Workflow Engine (AWE) that called the Approval Manager class to approve a transaction. The transaction failed because the Application Classes used in the Event notification handler used the %Component system variable. This would have been fine except %Component cannot be called from an IScript. To work around this, I wrapped the calls to %Component in a function that checks whether the execution context is a component. Here is the code:

Function GetComponentName() Returns String
If (%ContentType = "c") Then
Return %Component;
Else
Return "";
End-If;
End-Function;

If you are writing your code in a Page or a Component and use the %Component system variable, then you shouldn't have any problems. But, if your code is in a FUNCLIB or Application Class, a reusable component, then be aware that one of those "reuses" might be from PeopleCode that runs outside a Component (IScript, AppEngine, Message Subscription, etc). If that is the case, then please be kind to the developer that follows you by wrapping your calls to %Component in a function that tests to see if your code is executing within a Component.

7 comments:

Vishal said...

Hi Jim
I hope you would be able to help me.
I am currently working on designing approval workflow through AWE-PS8.9 Financial for the Requisition based on the user tree.
I have written SQLs to fetch the appropriate User from the tree, to route the request for approval to appropriate user. But I am facing an issue here. The approval process is working till the first step. If the amount is higher so that I need second step approval, the screen is timing out.
I ran the queries at the database and they are working fine.

Could you please guide what might be the issue?

Kind Regards
Vishal

Jim Marion said...

@Vishal, Did you run an SQL trace? Do you use Oracle? If so, can you tkprof a database trace file? PeopleSoft's component processor does interesting things with SQL, especially SQL that involves OPRID. An SQL trace will reveal the SQL that PeopleSoft is using, which might be different than the SQL you specified.

If it isn't SQL related, then I suggest you post a question on the OTN PeopleSoft Forum. Likewise, if you have support, you can open a case with GSC. Once you resolve the issue, please post the answer here for the benefit of the community as others may have the same question.

uffe_graa said...

Jim-

I recently purchased your Tips & Techniques book and without it I don't think I would have got a handle on AWE.

I have a question that you might be kind enough to help me with. I've searched far and wide, but haven't seen to come across what I need.

When using AWE to create a worklist entry, is there a way to control the text that is displayed as a link on the Worklist page.

Currently, it appears to be putting things like the key values and what might be the AWE Process Definition in there.

It would be nice if I could have control over what to display as part of executing the AWE.

Any help would be appreciated.

Thanks again for the book, it is very helpful.

-Uffe

Jim Marion said...

@Uffe, You ask a very good question. I don't believe there is a delivered method for accomplishing what you require. I dug through some of the code and it looks like the PeopleCode that generates the worklist description is in Record Field PeopleCode: PSWORKLIST.BUSPROCNAME.RowInit. It seems that changing this label would require you to modify the PeopleCode in this event. Working backwards from the PeopleCode, the link text is in field WORKLIST2.WF_HTMLAREA. The display value seems to come from WORKLIST2.DESCR254_MIXED. If you look through the code for WORKLIST2.DESCR254_MIXED, you can see that the PeopleCode does, in fact, iterate over the keys from the approval's work list record.

Velu K said...

Hi Jim,

I have some questions in reading the IBInfo elements in a synchronous non-rowset based message. Tools Version : 8.49.

I need to read the CONTENTSECTIONS element inside my handler app class peoplecode. I am seeing the below code supported only in 8.53.
&MSG.IBInfo.GetNumberOfAttributes();
&MSG.IBInfo.GetAttributeName (index);
&MSG.IBInfo.GetAttributeValue (index);

Could you please let me know on how we can read the contentsections element and its details?

Thanks
Velu

Jim Marion said...

@Velu, I don't have an example in front of me. You might want to post your question in the PeopleSoft General OTN Forum.

Unknown said...

Hi Jim
I hope you would be able to help me.
The scenario is I have ticket ID that would generate automatically and I give First Ticket ID as NEW When we are going to add new ticket ID For approval. I write code in saveprechange but it won't work. Can You Please Help me to resolve this.