Custom field Of Date/Time Picker is NULL on Create Transition

Rosy Salameh September 7, 2014

Hi Atlassians,

I developed a validator that checks if the value of a Custom Field is EMPTY and I have added this validator on the Create Transition of my WF.
But, when the Custom field is Of Date/Time Picker, the value is rendered NULL. This is something weird because if the Type is Free Text, I'm obtaining the value without any problem. In plus, my code works perfectly on other transitions. Is there something special from the type of field on the Create Level?
My snipped of code inside my validator is the following:

public void validate(Map transientVars, Map args, PropertySet ps) throws InvalidInputException, WorkflowException
{
    Issue issue = (Issue) transientVars.get("issue");
    CustomField customFieldParam = customFieldManager.getCustomFieldObject(Long.valueOf(13519));
    try {
        String currentCustomFieldParamValue = getCustomFieldStringValue(issue, customFieldParam);
    }
    catch (Exception e)
    {
        log.error(e);
    }
    if( StringUtils.IsNotEmpty(currentCustomFieldParamValue))
    {
        throw new InvalidInputException("Exception through Validator!");
    }
}
public String getCustomFieldStringValue(Issue issue, CustomField customField) throws Exception {
    String customFieldStringValue = "";
    Object value = issue.getCustomFieldValue(customField);
    if(value == null){
        customFieldStringValue = "";
    }
    else if(value instanceof Option) {
        customFieldStringValue = ((Option) value).getValue();
    }
    else if(value instanceof String) {
        customFieldStringValue = (String) value;
    }
    else if(value instanceof java.sql.Timestamp)
    {
        Date date = (Date)(customField.getValue(issue));
        DateFormat localDateFormatWithoutSeconds = new SimpleDateFormat("yyyy-MM-dd HH:mm");
        customFieldStringValue = localDateFormatWithoutSeconds.format(customfieldDateInUserTimeZone);
    }
    log.debug("Custom Field " + customField.getName() + " has the following string value: " + customFieldStringValue);
    return customFieldStringValue;
}

===> In Summary, getValue of customfield is rendering NULL on CREATE transition only for Date/Time types

P.S:
1- 13519 is the ID of my Date/Time Custom Field
2- In getCustomFieldStringValue function, when value is instanceof String, everything is OK. The problem is with instanceof java.sql.Timestamp.

Thanks,
Rosy

1 answer

0 votes
Rosy Salameh September 7, 2014

Hi again guys,

I was able to fix it by replacing: Date date = (Date)(customField.getValue(issue)); 

==>

Date date = (Date)(issue.getCustomFieldValue(customField));

Apparently, customField.getValue(issue) is not working with Date/Time CF onCreate Transition.


Thanks,

Rosy

 

Suggest an answer

Log in or Sign up to answer