Heads up! On March 5, starting at 4:30 PM Central Time, our community will be undergoing scheduled maintenance for a few hours. During this time, you will find the site temporarily inaccessible. Thanks for your patience. Read more.
×Hello,
I want to do the following operations with ScriptRunner, but I always get errors. I asked chatgpt and it gave an error again.
Summary (text) field must be at least 10 characters. (Validator)
The Details field is mandatory when the Reason (select list) field is selected in Jira. (Validator)
The End Date (Date Time Picker) field cannot be selected older than the System time. (Validator)
I am attaching the scripts given by chatgpt as images.
I tried the Summary and Reason script in the "Create" transition.
I tried the End Date script in the transition linking to "Resolved".
It is very important for me. Can you help please?
I used this site https://leap.scriptrunnerhq.com/expression but I didn't understand it. How do I add the output it gives me to the transition section?
Hi, you are confusing Jira Server scripts for Jira Cloud, I leave you the scripts that will help you in Jira Cloud
Validator for "Summary" Field
// Check if the summary length is at least 10 characters
if (issue.fields.summary?.length() >= 10) {
return true
} else {
return false
}
Validator for "Reason" and "Details" Fields
def reasonFieldId = "customfield_XXXXX" // Replace with the ID of the "Reason" field
def detailsFieldId = "customfield_YYYYY" // Replace with the ID of the "Details" field
// Retrieve the values of the fields
def reason = issue.fields[reasonFieldId]?.value
def details = issue.fields[detailsFieldId]
// If "Reason" is "Jira" and "Details" is empty, validation fails
if (reason == "Jira" && !details) {
return false
} else {
return true
}
Validator for "End Date"
def endDateFieldId = "customfield_ZZZZZ" // Replace with the ID of the "End Date" field
def endDate = issue.fields[endDateFieldId]?.isoDate
def now = ZonedDateTime.now()
// Check if the end date is in the future
if (endDate && ZonedDateTime.parse(endDate).isAfter(now)) {
return true
} else {
return false
}
If you have any questions or want to do something specific, don't hesitate to ask.
First of all, thank you very much. (:
I tried, but I got an error. I share the details below.
Expression Log
{
"timestamp": "2024-10-09T17:22:03.323Z",
"webhookEvent": "jira_expression_evaluation_failed",
"expression": "def reasonFieldId = \"customfield_10071\"\ndef detailsFieldId = \"customfield_10073\"\n\ndef reason = issue.fields[reasonFieldId]?.value\ndef details = issue.fields[detailsFieldId]\n\n\nif (reason == \"Jira\" && !details) {\n return false\n} else {\n return true\n}",
"errorMessages": [
"Jira expression failed to parse: line 1, column 5:\n=, =>, ., ?., [, ?.[, (, *, /, %, +, -, <, <=, >, >=, ==, !=, &&, ||, ??, ?, ; or EOF expected, reasonFieldId encountered."
],
"context": {
"issue": {
"fields": {
"summary": "1231231231233213",
"issuetype": {
"self": "https://hbtestcase.atlassian.net/rest/api/2/issuetype/10013",
"id": "10013",
"description": "",
"iconUrl": "https://hbtestcase.atlassian.net/rest/api/2/universal_avatar/view/type/issuetype/avatar/10309?size=medium",
"name": "Support",
"subtask": false,
"avatarId": 10309,
"hierarchyLevel": 0
},
"assignee": null,
"priority": {
"self": "https://hbtestcase.atlassian.net/rest/api/2/priority/3",
"iconUrl": "https://hbtestcase.atlassian.net/images/icons/priorities/medium.svg",
"name": "Medium",
"id": "3"
},
"status": null
}
},
"project": {
"self": "https://hbtestcase.atlassian.net/rest/api/2/project/10001",
"id": "10001",
"key": "HBHC",
"assigneeType": "PROJECT_LEAD",
"name": "HB Help Center",
"roles": {},
"avatarUrls": {
"48x48": "https://hbtestcase.atlassian.net/rest/api/2/universal_avatar/view/type/project/avatar/10419",
"24x24": "https://hbtestcase.atlassian.net/rest/api/2/universal_avatar/view/type/project/avatar/10419?size=small",
"16x16": "https://hbtestcase.atlassian.net/rest/api/2/universal_avatar/view/type/project/avatar/10419?size=xsmall",
},
"projectTypeKey": "service_desk",
"simplified": false,
"style": "classic",
"properties": {}
},
"serviceDesk": {
"id": "1",
"projectId": "10001",
"projectName": "HB Help Center",
"projectKey": "HBHC",
"_links": {
"self": "https://hbtestcase.atlassian.net/rest/servicedeskapi/servicedesk/1"
}
},
"user": {
"accountId": "712020:9ea6ee70-d7ba-4468-b817-4d14e40860a7",
"avatarUrls": {
},
"displayName": "Barış Özer",
"active": true
},
"config": {
"expression": "def reasonFieldId = \"customfield_10071\"\ndef detailsFieldId = \"customfield_10073\"\n\ndef reason = issue.fields[reasonFieldId]?.value\ndef details = issue.fields[detailsFieldId]\n\n\nif (reason == \"Jira\" && !details) {\n return false\n} else {\n return true\n}",
"errorMessage": "If the Reason field is selected as \"Jira\", the \"Details\" field must be filled.",
"description": "Reason and Details field Validator",
"uuid": "68562683-c183-45dd-9c44-c0ed9a0ca61e",
"enabled": true
},
"transition": {
"name": "Create",
"from": null,
"id": 1,
"to": {
"self": "https://hbtestcase.atlassian.net/rest/api/2/status/1",
"description": "",
"iconUrl": "https://hbtestcase.atlassian.net/images/icons/statuses/open.png",
"name": "Open",
"id": "1",
"statusCategory": {
"self": "https://hbtestcase.atlassian.net/rest/api/2/statuscategory/2",
"id": 2,
"key": "new",
"colorName": "blue-gray",
"name": "New"
}
}
}
},
"validator.id": "2c752a0e-ea13-4ae7-9cf7-fb7300a8ef8c",
"workflow.name": "HBHC: Jira Service Management IT Support Workflow",
"moduleKey": "script-workflow-validators"
}
After selecting the "Reason" field "Jira" on the Create Screen, I left the "Details" blank. After clicking Create it gave this error.
Kind regards,
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Barış Özer I apologize, I made them with a listener in mind, so I'll leave them here so they can be in a validator.
Use the fields you had on hand, but it would just be changing them.
Validator for "Summary" Field
Validator for "Reason" and "Details" Fields
issue.customfield_11361?.value == "Contributor" && (!issue.customfield_11359 || issue.customfield_11359.trim() == "")
Validator for "End Date"
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi, @Barış Özer
ChatGPT examples are mostly correct, but they are for on-premise solution.
If I understood tags, that you added, right, you are using Jira Cloud.
You need to use validators based on expressions. You can find examples here:
https://docs.adaptavist.com/sr4jc/latest/features/workflow-extensions/jira-expression-examples
First example is exactly what you're looking for - summary, larger than 10 symbols.
Also there are examples for other field types.
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.
It's an example. You need to know basics of programming.
For summary checking you can use:
if (issue.summary.length >= 10 ) {
return true
} else {
return false
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Evgenii
I created an issue.
Summary I wrote more than 10 characters, but I was still able to create it.
Where am I doing wrong?
I added "validator" to the create transition.
I think if I learn this, I can do it for the rest.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I don't understand what you are trying to make them.
That was your question:
> Summary (text) field must be at least 10 characters. (Validator)
"at least" means, that it must be 10 symbols or longer.
If you want summary exactly 10 symbols long - it's "issue.summary.length == 10" condition.
If you want summary no longer than 10 symbols - it's "issue.summary.length <= 10"
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Evgenii
I'm really, really sorry.
I've been trying for 2 days and I can't see it :'(
The Details field is mandatory when the Reason (select list) field is selected in Jira. (Validator)
The End Date (Date Time Picker) field cannot be selected older than the System time. (Validator)
How can I do it for the above 2 items? Can you give a recommendation or website?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I don't know customfiled IDs in your system. You have to find it by yourself.
> The End Date (Date Time Picker) field cannot be selected older than the System time. (Validator)
issue.customfield_11111 ?
new CalendarDate(issue.customfield_11111) <= new CalendarDate() :
false
> The Details field is mandatory when the Reason (select list) field is selected in Jira. (Validator)
if (issue.customfield_22222) {
if(issue.customfield_33333) {
return true
} else {
return false
}
}
Instead of 11111, 22222, 33333 use customfield ids from your system
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Evgenii
I got an error like below.
customfield value is correct. I checked.
I added a resolve transition, is that correct?
After the Resolve status, you can see on the right "End Date" field will be written manually. (Cannot be selected older than system time)
Where and what am I doing wrong? :(
> The Details field is mandatory when the Reason (select list) field is selected in Jira. (Validator)
if (issue.customfield_22222) {
if(issue.customfield_33333) {
return true
} else {
return false
}
}
This didn't work either :(
Thank you very much for the help..
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I tried the last one you sent, but it still didn't work :(
I don't know what to do. I've run out of ideas.
Is it the right time to give up?
I don't know where is wrong...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Evgenii
The End Date (Date Time Picker) field cannot be selected older than the System time. (Validator)
I did it, it works.
But I still couldn't find the one below...
The Details field is mandatory when the Reason (select list) field is selected in Jira. (Validator)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
if (issue.customfield_22222) {
return issue.customfield_33333 != null
} else {
return true
}
Try this
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Evgenii
Sorry, it gave an error :(
I selected Reason field Jira and left Details blank. I pressed Create and it gave the following error. It acts as if the Details field is empty.
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.