The UCID is in the SIP User-to-User header and is indicated by the FA08 code in the Hex. So first set a variable using the following:
<var name="U2U" expr="session.connection.protocol.sip.headers['user-to-user']"/>
The actual UCID is comprised of three different sections. The following Javascript will parse those out and reassemble into the decimal version of the UCID:
function parseUCID(u2u) {
var parseUCIDfromU2U = u2u.split(/FA\d{2}/);
var UCID = parseUCIDfromU2U[1];
var hexChars = u2u.match(/FA(\d{2})/);
hexChars[1] /= 2;
var ucid1 = UCID.substr(0,(hexChars[1]));
var ucid2 = UCID.substr(hexChars[1],hexChars[1]);
var ucid3 = UCID.substr((hexChars[1]*2),(hexChars[1]*2));
ucid1 = parseInt(ucid1,16);
ucid2 = parseInt(ucid2,16);
ucid3 = parseInt(ucid3,16);
ucid1 = prependZeros(ucid1,5);
ucid2 = prependZeros(ucid2,5);
ucid3 = prependZeros(ucid3,10);
return "" + ucid1 + ucid2 + ucid3;
}