Skip to main content

This content has been archived and is no longer being updated. Links may not function; however, this content may be relevant to outdated versions of the product.

Support Article

Parameters for Format Values in Report Definition incorrect

SA-14054

Summary



In a Report Definition rule, specifying a control (for example, pxDateTime) in Format Values for a column, does not display the correct parameters for the control. Hence, unable to format dates with the DateTime format, 2 days, 5 hours ago, with second number Cutoff as 1.


Error Messages



Not Applicable


Steps to Reproduce



1. In Report Definition rule’s Design tab, add a datetime property (for example, pxCreateDateTime) to section Columns To Include.
2. Specify control, pxDateTime, for the column’s parameter, Format Values.
3. Click the magnifying glass icon to view the parameters.
4. Popup window displays the parameters but not the expected parameters for the control pxDateTime. Also, the value for String Type always defaults to Text.


Root Cause



The format list in a report definition includes out-of-the-box controls. The parameter window for any out-of-the-box control in the Report Definition is the same. The string type is always defaulted to Text.
This functionality has been enhanced in the later versions PRPC 6.3 SP1 onwards to display only the format values for any control used under Format Values.

Resolution



Create a new non auto generated control and add the below code. Use this control in the report definition as the format value for the DateTime property.

<%
ClipboardProperty curProp = tools.getActive();
char propType = '\u0000';
propType = curProp.getType();
String strTimeZone = tools.findPage("pxRequestor").getString(".pyUseTimeZone");
Date propDateValue = curProp.toDate();
int secNoCutoff = 1;
String secCutoff = tools.getParamValue("secNoCutoff");

if (!"".equals(secCutoff)) {
    try {
        secNoCutoff = Integer.parseInt(secCutoff);
    } catch (Exception e) {}
}

Calendar currCal = null, propCal = null, tempCal = null;
if (propType == ImmutablePropertyInfo.TYPE_TIMEOFDAY) {
    currCal = new GregorianCalendar(TimeZone.getTimeZone(strTimeZone));
    int date = currCal.get(Calendar.DATE);
    int month = currCal.get(Calendar.MONTH);
    int year = currCal.get(Calendar.YEAR);
    int hour = currCal.get(Calendar.HOUR_OF_DAY);
    int min = currCal.get(Calendar.MINUTE);
    int sec = currCal.get(Calendar.SECOND);
    currCal.setTimeZone(TimeZone.getTimeZone("GMT"));
    currCal.set(year, month, date, hour, min, sec);
    propCal = new GregorianCalendar(TimeZone.getTimeZone("GMT"));
    propCal.setTime(propDateValue);
    propCal.set(year, month, date);
} else if (propType == ImmutablePropertyInfo.TYPE_DATE) {
    currCal = new GregorianCalendar(TimeZone.getTimeZone(strTimeZone));
    int date = currCal.get(Calendar.DATE);
    int month = currCal.get(Calendar.MONTH);
    int year = currCal.get(Calendar.YEAR);
    currCal.setTimeZone(TimeZone.getTimeZone("GMT"));
    currCal.set(year, month, date, 0, 0, 0);
    propCal = new GregorianCalendar(TimeZone.getTimeZone("GMT"));
    propCal.setTime(propDateValue);
} else {
    currCal = new GregorianCalendar(TimeZone.getTimeZone(strTimeZone));
    propCal = new GregorianCalendar(TimeZone.getTimeZone(strTimeZone));
    propCal.setTime(propDateValue);
}
int toAdd = ((propCal.getTimeInMillis() - currCal.getTimeInMillis()) > 0) ? 1 : -1;
String sDisplay = tools.getLocalizedTextForString(".pyFormatter", toAdd == 1 ? "from now" : "ago");

StringBuffer sBuff = new StringBuffer();
int years = 0, months = 0, days = 0;
long diff = 0;
if (propType != ImmutablePropertyInfo.TYPE_TIMEOFDAY) {
    if (toAdd == 1 && propType == ImmutablePropertyInfo.TYPE_DATE) {
        propCal.add(Calendar.SECOND, 1);
    }
    // years
    diff = (propCal.getTimeInMillis() - currCal.getTimeInMillis()) / 60000;
    diff /= 527040;
    years = (int) diff;
    currCal.add(Calendar.YEAR, years);
    years = Math.abs(years);
    tempCal = (GregorianCalendar) currCal.clone();
    tempCal.add(Calendar.YEAR, toAdd);
    while ((toAdd == 1 && tempCal.getTimeInMillis() <= propCal.getTimeInMillis()) || (toAdd == -1 && tempCal.getTimeInMillis() >= propCal.getTimeInMillis())) {
        years++;
        currCal.add(Calendar.YEAR, toAdd);
        tempCal.add(Calendar.YEAR, toAdd);
    }
    // months
    diff = (propCal.getTimeInMillis() - currCal.getTimeInMillis()) / 60000;
    diff /= 44640;
    months = (int) diff;
    currCal.add(Calendar.MONTH, months);
    months = Math.abs(months);
    tempCal = (GregorianCalendar) currCal.clone();
    tempCal.add(Calendar.MONTH, toAdd);
    if ((toAdd == 1 && tempCal.getTimeInMillis() <= propCal.getTimeInMillis()) || (toAdd == -1 && tempCal.getTimeInMillis() >= propCal.getTimeInMillis())) {
        months++;
        currCal.add(Calendar.MONTH, toAdd);
        tempCal.add(Calendar.MONTH, toAdd);
    }
    //days
    diff = (propCal.getTimeInMillis() - currCal.getTimeInMillis()) / 60000;
    diff /= 1440;
    days = (int) diff;
    currCal.add(Calendar.DATE, days);
    days = Math.abs(days);
    diff = (int) Math.abs((propCal.getTimeInMillis() - currCal.getTimeInMillis()) / 3600000);
    int hours = (int) diff;
    if (years > 0) {
        sBuff.append(years).append(" ").append(tools.getLocalizedTextForString(".pyFormatter", (years > 1) ? "years" : "year"));
        if ((secNoCutoff == -1 || years < secNoCutoff) && months > 0) {
            sBuff.append(", ").append(months).append(" ").append(tools.getLocalizedTextForString(".pyFormatter", (months > 1) ? "months" : "month"));
        }
    } else if (months > 0) {
        sBuff.append(months).append(" ").append(tools.getLocalizedTextForString(".pyFormatter", (months > 1) ? "months" : "month"));
        if ((secNoCutoff == -1 || months < secNoCutoff) && days > 0) {
            sBuff.append(", ").append(days).append(" ").append(tools.getLocalizedTextForString(".pyFormatter", (days > 1) ? "days" : "day"));
        }
    } else if (days > 0) {
        sBuff.append(days).append(" ").append((days > 1) ? "days" : "day");
        if ((secNoCutoff == -1 || days < secNoCutoff) && hours > 0 && propType != ImmutablePropertyInfo.TYPE_DATE) {
            sBuff.append(", ").append(hours).append(" ").append(tools.getLocalizedTextForString(".pyFormatter", (hours > 1) ? "hours" : "hour"));
        }
    } else if (propType == ImmutablePropertyInfo.TYPE_DATE) {
        out.print(sBuff.append(tools.getLocalizedTextForString(".pyFormatter", "today")).toString());
        return;
    }
}
if (propType != ImmutablePropertyInfo.TYPE_DATE && (years + months + days) == 0) {
    diff = (int) Math.abs((propCal.getTimeInMillis() - currCal.getTimeInMillis()) / 60000);
    int min = (int) diff;
    int hours = min / 60;
    min = min % 60;
    if (hours > 0) {
        sBuff.append(hours).append(" ").append(tools.getLocalizedTextForString(".pyFormatter", (hours > 1) ? "hours" : "hour"));
        if ((secNoCutoff == -1 || hours < secNoCutoff) && min > 0) {
            sBuff.append(", ").append(min).append(" ").append(tools.getLocalizedTextForString(".pyFormatter", (min > 1) ? "minutes" : "minute"));
        }
    } else if (min > 1) {
        sBuff.append(min).append(" ").append(tools.getLocalizedTextForString(".pyFormatter", (min > 1) ? "minutes" : "minute"));
    } else if (min > 0) {
        sBuff.append(tools.getLocalizedTextForString(".pyFormatter", "about a minute"));
    } else {
        sBuff.append(tools.getLocalizedTextForString(".pyFormatter", "less than a minute"));
    }
}
out.print(sBuff.append(" ").append(sDisplay).toString());
return;
%>

Published September 10, 2015 - Updated October 8, 2020

Was this useful?

0% found this useful

Have a question? Get answers now.

Visit the Collaboration Center to ask questions, engage in discussions, share ideas, and help others.

Did you find this content helpful?

Want to help us improve this content?

We'd prefer it if you saw us at our best.

Pega Community has detected you are using a browser which may prevent you from experiencing the site as intended. To improve your experience, please update your browser.

Close Deprecation Notice
Contact us