AnsweredAssumed Answered

Task Session ID in PX Policy

Question asked by ScottHamilton on Nov 1, 2016
Latest reply on Jun 26, 2018 by ausch02

This is an issue I had and I've seen a few other posts about, so I thought I'd toss in the solution in case it is useful to anyone else.

 

So the problem: being able to access the current task session ID in a PX policy.

 

There are a number of reasons you might need this - we use it for auditing in an external db, as well as putting it in emails so we can track the exact task the email came from and thus find it easily in the VST.

 

PX Policy (at least our version 12.6.6 - not sure about later) has no way of pulling this task info. However you _can_ get that information with a BLTH. So my solution was to place a JavaScript BLTH on the tasks that I need the task session ID for to insert the id as a custom 'task session attribute'. Then we leverage the get Task Session Attribute option in the Data elements of a PX policy to get it.

 

Here's the JavaScript code. It creates two custom Task Session Attributes, one for the task session ID, and one for the creation time of the task session.

 

---

 

function handleStart(blthContext, errorMsg) {

try {
    var taskID = blthContext.getSessionId();
    var now = blthContext.getSessionCreateTime();
    var df = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    blthContext.setSessionAttribute("taskID",taskID);
    blthContext.setSessionAttribute("date",df.format(now));

}
catch (exception) {
    errorMsg.reference = "Cannot set Task ID or Create DateTime";
    return false;
}
return true;
}

 

---

 

Then in the PX policy, I create a data element like this:

Outcomes