How to get current project and issuetype in method validateFromParams method in my customfield plugin

vijaya reddy December 1, 2013

HI,

I have written a customfield extending TextCFType . I override method

public void validateFromParams(CustomFieldParams relevantParams,
ErrorCollection errorCollectionToAddTo, FieldConfig config)

Here i want to put validation logic based on current project and issuetype. But i do not find any api to get those details from parameters.

Can anybody suggest a solution?

Regards,

Vijaya Kumar Reddy

10 answers

1 vote
rambabu patina
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 1, 2013

Hi Vijay,

You can use ComponentAccessor to retrive the projects and issue types. Hope this helps you. You can use it by importing ComponentAccessor in the class.

-Patina

0 votes
Alied Perez
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 23, 2014

Actually what I see is a map of the keys defined this way (as the tiny-comment-no-one-seems-to-read-before-removing-and-fails-to-appear-in-any-other-tutorial-or-documentation advices to do):

fieldId + ':' + key

This bundles all values from the same key and creates an entry like key => [values]

if your inputs have the name only fieldId, they go to the null key.

So I have my own keys, and that's it; no issue nor way to find it; nada, rien, niente. I'm working in a standalone server.

0 votes
EddieW
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 23, 2014

I was mistaken, the value I saw locally was "requireProjectId" - but non idea where it came from. - do you only see the "null" param?

SDK Locally

[INFO] [talledLocalContainer]  ====================KEY: null
[INFO] [talledLocalContainer]  ====================KEY: issue
[INFO] [talledLocalContainer]  ====================KEY: requireProjectIds

Test Standalone

[INFO] [talledLocalContainer]  ====================KEY: null

Also the issue you linked to ius resolved - can't vote for it, and likely ignored by support. I cloned to a new ticket and cited the quesitons I have found here - https://jira.atlassian.com/browse/JRA-37627

0 votes
Alied Perez
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 23, 2014

Hmm, I have filled the code with logs, but have seen no issue around.

Where do you say "requireIssue" is to be set?

I found an ancient RFE[1] from 2009 with this very request. Maybe if we gather enough votes they do something...

[1]https://jira.atlassian.com/browse/JRA-19321

0 votes
EddieW
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 23, 2014

Users of JIRA 6.2.1 (and above?) can get this from the passed Params.

public void validateFromParams(CustomFieldParams relevantParams,ErrorCollection errorCollectionToAddTo, FieldConfig config) {
  Issue passedIssue = (Issue) relevantParams.getFirstValueForKey(ISSUE_KEY);
        


    // safety catch
    if(null != passedIssue){             
        log.error("Unable to get the current issue during Edit, cannot validate !!");
        errorCollectionToAddTo.addError(fieldName, "There is an issue with the Reservation system, please report to Support.  You may clear this field to save other updates.");
        return;
    }
    ...
}

See my other question for the cautionary tail https://answers.atlassian.com/questions/276206/issue-missing-from-relevantparams-in-customfield-validate for JIRA versions < 6.2.1

hirok September 30, 2014

Hi, I have the same problem. I want to know current project and issuetype in the validateFromParams when I create an issue. I installed my custom field into JIRA 6.3.4 and tried to debug. There is no issue in the relevantParams. When I edit an existing issue, I can see com.atlassian.jira.internal.issue_id. But there is nothing during the creation. Any advice would be helpful. hiro

0 votes
EddieW
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 23, 2014

I was able to get this from Issue issue = (Issue) revelantParams.getFirstValueWithKey("issue");


But I changed somehting and that key, along with "requireIssue" are missing. I assume "requireIssue" is specified somewhere as true will make it come back, but I hanvent found where yet.

https://answers.atlassian.com/questions/276206/issue-missing-from-relevantparams-in-customfield-validate

0 votes
Alied Perez
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 17, 2014

Hi, I need to validate the issue's status and can't get the issue in MyCustomFieldType.validateFromParams(). Has anyone found a solution?

Thanks.

0 votes
Saurabh Arora February 12, 2014

No. It is still a open question.

0 votes
Holger Schimanski
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 11, 2014

Did you found a solution? Having the same problem...

0 votes
vijaya reddy December 1, 2013

Hi Rambabu,

It looks you misunderstood my query. I want to get current issue's project and issuetype in validateFromParams method. is there a way?

Regards,

Vijaya Kumar Reddy

rambabu patina
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 2, 2013

Hi Vijay,

Is your question is to get the issue from the params? If you are able to get the issue then you can get current issues project and issue type using Issue.getProjectObject() and getIssueTypeObject().

Thanks,

Rambabu

Alied Perez
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 17, 2014

If you are able to get the issue

That's exactly what I'm trying to do...

Suggest an answer

Log in or Sign up to answer