Discussion

Get active thread from Requestor
Hi,
Wanted to know if there is any API function to get the current thread from requestor.
We are putting one icon at the header of the portal but in the work panel if user opens 2,3 threads how can we get the latest thread or active thread through API call on icon action.
-
Like (0)
-

u can write java step and use tools.getThread() api to get the thread object
PRThread threadName = tools.getThread();
threadName.getName(); give you the current thread Name

thanks for response.
will try and update if we face any issue.

Hi,
Its workking if i put html inside workpanel (work-object level harness), but not working from header.
Any other way to achieve the same?

Let me explain you the issue here,
We have one composite portal in which we are refferering a harness rule which contains header (top panel) and work area (center panel).
Our requirement is to get the thread id & details from work area panel whenever user clicks on icon which is present on header.
Your suggestion is only working if i put html/js code inside work area panel, not from header.

the code didnt work because header (top panel) always run in the Open Portal or Standard Thread context. You can trace the stream rules to find under which hread context the header is rendering

The other option you can try is get the current thread name from pxThreadPage and use the below code
String threadname = tools.findPage("pxThread").getString("pxThreadName");
PRThread myCurrentthread = tools.getThread().getRequestor().getThread(threadName);

No luck .. its always returning "OpenPortal"
just added below line after ur code.
---------------------------------------
String threadname = tools.findPage("pxThread").getString("pxThreadName");
PRThread myCurrentthread = tools.getThread().getRequestor().getThread(threadName);
---------------------------------------
String myCurrentthreadname = myCurrentthread.getName();
alert(myCurrentthreadname); //output "OpenPortal"
also didnt understand 2nd line of your code, what does it do?

it gets the current state of thread and you can access the clipboard data using that thread information

thanks, but its always returning "OpenPortal" .(default threadID from header panel)

I do not know the solution but i assume you have already discussed with the business that the icon placement is not correct.
If you make this work they might come back to you asking to put where am i, attachments, audit trail icons etc also at the same place.
Ideally Icons which pull details to a specific case should be at work level only.
Thanks
Chiranjeevi

If you are on Pega 7 you can try this to get the Active thread ..
------------------------------------------------------------------------------------------------
PublicAPI tools = null;
PRThread thisThread = (PRThread)ThreadContainer.get();
if (thisThread != null)
{
tools = thisThread.getPublicAPI();
}
if (tools == null)
{
throw new com.pega.pegarules.pub.PRRuntimeError("Can't get a PublicAPI reference.");
}
try {
String portalName = tools.findPage("pxThread").getString("pxPortal");
ClipboardProperty dynamicContainerActiveThreadID = tools.getIfPresent("Declare_pyDisplay.pyDisplay("+portalName.trim()+").pyUIActive(1).pyThreadId");
if (dynamicContainerActiveThreadID != null) {
String threadId = dynamicContainerActiveThreadID.getStringValue();
if(!"".equals(threadId)) {
return threadId;
}
}
} catch (Exception ex) {
ex.printStackTrace();
}
return "STANDARD";
------------------------------------------

but our concern is that if we put icon on work level that will require huge amount of change in whole application, as there are multiple UI which we need to modify to achieve this.

Try to read this link, it might help
https://pdn.pega.com/forums/general-questions/sharing-information-between-prpc-threads