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

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

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
Community showcase
Posted Sep 18, 2018 in Jira

What modern development practices are at the heart of how your team delivers software?

Hey Community mates! Claire here from the Software Product Marketing team. We all know software development changes rapidly, and it's often tough to keep up. But from our research, we've found the h...

22,745 views 2 7
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you