Hi All,
I'm trying to put together a behaviour in scriptrunner, I'm pretty new to creating these so please bare with me.
In a nutshell, I have a custom field (State) when a value is selected (i.e. CA), I would need that particular custom field to display on screen (i.e. County CA). This is what I've put together so far, but I haven't had any success displaying the field when i select an option.
initialiser
def State = getFieldByName("State")
field
import com.atlassian.jira.component.ComponentAccessor
def State = getFieldByName("State")
//County List
def CountyCA = getFieldById("customfield_18914")
def CountyAL = getFieldById("customfield_18910")
def CountyAK = getFieldById("customfield_18911")
def CountyAR = getFieldById("customfield_18913")
def CountyAZ = getFieldById("customfield_18912")
CountyCA.setHidden(true)
CountyAL.setHidden(true)
CountyAK.setHidden(true)
CountyAR.setHidden(true)
CountyAZ.setHidden(true)
if (State == "CA")
{
//Show Fields
CountyCA.setHidden(false)
//Hide Fields
CountyAL.setHidden(true)
CountyAK.setHidden(true)
CountyAR.setHidden(true)
CountyAZ.setHidden(true)
}
Any suggestions on where I can go from here?
Thanks,
Norm
This has been extracted from Adaptavist documentation, modified it a little and tested in the Script Console and it works:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.util.json.JSONObject
final SD_PUBLIC_COMMENT = "sd.public.comment"
def commentManager = ComponentAccessor.getCommentManager()
def issueManager = ComponentAccessor.getIssueManager()
def properties = [(SD_PUBLIC_COMMENT): new JSONObject(["internal": false])]
commentManager.create(issue, user, "mi comentario", null, null, new Date(), properties, true)
Source:
https://scriptrunner.adaptavist.com/latest/jira/recipes/misc/jira-service-desk.html
@[deleted] It is works from script console. Also it works from postfunction, when you manually press on transition button.
But when you attach this postfunction to automatically passing workflow step ( for example on "create issue transition" or to some step that passes automaticaly wirh scriptrunner on some conditions) it creates internal comment, that is not visible on servicedesk script.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Evgeniy Buturlia This is because possibly the user who creates the comment is not an agent, that is, a user of the service-desk-agents group.
I tried the following script and it worked in a "create issue transition":
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.comments.CommentManager
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.util.json.JSONObject
final SD_PUBLIC_COMMENT = "sd.public.comment"
def issueKey = issue
def userManager = ComponentAccessor.getUserManager()
def CurrentUser = userManager.getUserByName("sysbot") as ApplicationUser // Test user, sd-agent
CommentManager commentManager = ComponentAccessor.getCommentManager()
def comment = "My external comment." // Comment
def properties = [(SD_PUBLIC_COMMENT): new JSONObject(["internal": false] as Map)]
commentManager.create(issueKey, CurrentUser,comment, null, null, new Date(), properties, true)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
This will now work, because when script runs from a non-servicedesk agent user, it can'not add comment with visibility level "public", even if comment user is servcedesk agent.
To make it work you need add this code before "commentManager.create(...)":
ComponentAccessor.getJiraAuthenticationContext().setLoggedInUser(ComponentAccessor.getUserManager().getUserByKey("sysbot"))
Where "sysbot" is user with servicedesk agent permission.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Evgeniy Buturlia i try and doesn't work. But i changed last argument of method to "false" and script add public comment.
commentManager.create(issueKey, CurrentUser,comment, false)
I wonder if this is correct
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Comment manager creates comment from CommentUser BUT it run's from current loggined in user. If current user can not post puclic comments, it will not be able to create public comment.
Last argument is responcible for dispatching event. You may read about it here : https://docs.atlassian.com/software/jira/docs/api/7.6.1/com/atlassian/jira/issue/comments/CommentManager.html#create-com.atlassian.jira.issue.Issue-com.atlassian.jira.user.ApplicationUser-java.lang.String-boolean-
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.