I have custom field as named "WARRANTY DATE" (date picker) , i need to get this field value and have to compare with system's date.
If WARRANTY DATE is before than SYSTEM'S DATE it has to give not walid else valid.
plz help me
I am new to groovy
Hi,
This code should work:
import com.atlassian.jira.component.ComponentAccessor
def customFieldManager = ComponentAccessor.customFieldManager
def warrantyField = customFieldManager.getCustomFieldObjectByName("WARRANTY DATE")
def warranty = issue.getCustomFieldValue(warrantyField)
def systemDate = new Date()
return warranty > systemDate
In this code, you take warranty date and system date and the return statement compares it. If warranty is before systemDate, it returns false and if warranty is after systemDate it returns true.
Regards,
Marcos
i am getting error as static type checking The variable (issue) is undeclared.
I have tried with underlyingissue and MutableIssue library but didnt work
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
Where are you running the script? Listener, Workflow, Console...?
Regards,
Marcos
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
Then you have to run this:
import com.atlassian.jira.component.ComponentAccessor
def issueManager = ComponentAccessor.issueManager
def customFieldManager = ComponentAccessor.customFieldManager
def warrantyField = customFieldManager.getCustomFieldObjectByName("WARRANTY DATE")
def issue = issueManager.getIssueByCurrentKey("DEMO-123")
def warranty = issue.getCustomFieldValue(warrantyField)
def systemDate = new Date()
return warranty > systemDate
Replacing "DEMO-123" for the key of the issue you want to check.
You can use the first version of the code when using a Listener or a Workflow script.
Regards,
Marcos
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I am not getting output
Although it is showing no error in executions.
Please help me to sort out this
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
In this image is how should it look to you after clicking "Run" on Script Console.
The output is in the "Result" tab.
Regards,
Marcos
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
yaa fine..
But do you knw how to execute this in script field using date picker custom field
I have tried it is showing invalid date
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I dont want to mention issue Key also. Ex(DEMO-123)
First version is fine but it has to show values valid or invalid when it compares.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
Could you please explain me what do you want to do?
As I understood, you have a field called "WARRANTY DATE" and you want to compare it with the system date.
What do you want to do with the result, or what else do you want to do?
Regards,
Marcos.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I want to display result whether date is VALID or INVALID in view screen of all issues under that project
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
Then you can add a script field (with HTML template) named for example "WARRANTY" and use this code:
import com.atlassian.jira.component.ComponentAccessor
def issueManager = ComponentAccessor.issueManager
def customFieldManager = ComponentAccessor.customFieldManager
def warrantyField = customFieldManager.getCustomFieldObjectByName("WARRANTY DATE")
def warranty = issue.getCustomFieldValue(warrantyField)
def systemDate = new Date()
if(warranty < systemDate){
return("<p style=color:red>INVALID</p>")
}else{
return("<p style=color:green>VALID</p>")
}
You should also configure it for the context and screen that you want it to work.
In this image you can see how did I configure the script field.
Hope it helps.
Regards,
Marcos
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I am getting errors in 12 and 14th line as
cannot return value of type java.lang.string on method returning type java.lang.double
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Its k Marcos
It is working now.
Thanks lot
Greatly appreciate.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
It's nice to see that it works.
Please approve the first answer so it's a valid one.
Regards,
Marcos
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi..
Marcos
Do u know how map this script using behaviours ?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
What do you want to do with the behaviour?
The Script Field isn't enough for you?
Regards,
Marcos.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Actually we don't want to add script field in that screen.
That's why i need to use behaviours.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Do we able to show a result in that WARRANTY DATE field only?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
By using this script and Behaviours can we able to pop up the Result in View screen ?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Getting error in return statement.
Cannot find matching method
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Please, paste the full error.
Without the full error I can't know if it's a typo or a code error.
Thanks
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
java.lang.Object#compareTo(java.util.Date). Please check if the declared type is right and if the method exists.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
Did you run the script?
The error that you are reporting is the error that shows the red underlined >, right?
It's because, in script, warranty has no type defined, but in execution time it should work.
I'd just tried the script that I sent to you and it worked perfectly to me.
Regards,
Marcos
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.