I have created a behaviour using behaviour plugin for populating default text in Description field while creating an issue. Mapping is for a Project say "Project A" and issue type "Change Request".
Behaviour works fine for correct selection of the Project and Issue Type. However to make it more appropriate, the default text should get clear on selection of the different issue type which does not happen with the current script. Can anyone help me with achieving this behaviour?
Following is the script i am using in the Initialiser.
def desc = getFieldById("description") def defaultValue = """Example Text """ if (getActionName() == "Create"){ desc.setFormValue(defaultValue) } else { }
Thank in Advance.
Cheers
Instead of putting the script in the initializer, I'd put it in a server-side script on the Issue Type field. To remove your added text whenever someone switches to/from the issue type, the best thing to do would be to get the currently input value and just use a .replaceAll to remove the example text.
You can limit this behaviour to a particular project when you setup the mapping.
Also, as a side note, I thought I'd make it so the default value gets prepended to the description. That way, if they've already entered something when they switch between issue types, their other text doesn't get overwritten.
def desc = getFieldById("description") def issueType = getFieldById("issuetype") def defaultValue = """Example Text """ def currentValue = desc.getFormValue() /* Replace 100001 with your issue type's ID; Alternatively, you can use the IssueTypeManager class to get the ID based on the Issue Type's name and other properties for clarity, and to harden the script against Issue Type changes later */ if (issueType.value == "100001"){ desc.setFormValue("$defaultValue - $currentValue") } else { desc.setFormValue(desc.value.toString().replaceAll("Example Text ", "")) }
This does have the drawback that someone might type in "Example Text" themselves and see it removed. That said, it will preserve anything they put into the description field that wasn't the phrase "Example Text".
Note: I'm assuming that you have updated to a version of ScriptRunner that includes Behaviours as a feature, and aren't using an old version of the separate Behaviours Plugin.
Thanks for the prompt response. Yes, I am using Script Runner which has Behaviour as feature.
I think I have not clarified the requirement properly. Sorry for the confusion.
Above suggested script by you replaces the "Example Text" on the action other than "Create", but i do not want that. I want to clear the default text i.e. "Example Text" on 'Create' action only when I change to different Issue Type than Change Request on the same pop-up screen. I have mappings for a project and Issue Type Change Request.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
That makes more sense... I just sort of assumed the "if" condition was the one you wanted, and didn't look too closely!
I've updated my answer.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I found my mistake that in the mapping section i was mapping with Project and only one issue type"Change Request" which was making not to trigger script when there is a selection of different issue type. I made the changes and script works fine.
Somehow desc.setFormValue(desc.value.toString().replaceAll(
"Example Text "
,
""
))
didnt work for me.. but the basic functionality was enough for me for now so will investigate why it is not working for me. If you could guess any errors, please let me know.
Thanks Jonny for your help. Much appreciated. Have great time
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Suhas P What changes did you made here?
Currently, I am also facing the same problem and mapped it to my Project and a particular issue type. Why is it wrong?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Sanket Mane you should add additional condition for issue type along with getActionName() == "Create" as below. and I use this code in initialiser.
In mapping use a project and All Issue Types (not a specific issue type), then the code will run for every issue type selection and set or clear the description based on the issue type selection.
def desc = getFieldById("description")
def defaultValue = """Example Text """
if ((getActionName() == "Create") && (issueContext.issueType.name =="Task")){
desc.setFormValue(defaultValue)
}
else {
desc.setFormValue("")
}
Beware that clear field will clear the description field completely . So you can use it or you can also combine it with the login given by Jonny above in the answer with replaceAll to clear only default text and keep the other text. Depends on you how you want.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
This seems to have helped but caused another issue. Due to the implementation of this behaviour- whenever we try to edit the description field- it doesnt show the required content inside it. I see all the content on the View Screen but when I click on the edit screen Description field appears to be empty.
Can you help me on it.
Thank you
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Ohh
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Sanket ManeOhh I think its because of the Else statement. Modify the Else statement like this
def desc = getFieldById("description")
def defaultValue = """Example Text """
if ((getActionName() == "Create") && (issueContext.issueType.name =="Task")){
desc.setFormValue(defaultValue)
}
else ((getActionName() == "Create") && (issueContext.issueType.name !="Task")){
desc.setFormValue("")
}
else {
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I have the same problem. The "description"-field has two display mode: Text and visual.
If you stay in the "Text"-Mode, then the field gets updated correctly, but if i am in the "Visual"-Mode then the description field gets not updated.
Do you have an idea how to force the update of the visual mode?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@[deleted] did you find solution for your problem? I am facing the same issue when in visual mode behaviour code is not firing.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi everyone,
I have the same problem, Description field doesn't clean up when the conditions of the behaviour are not fullfilled.
I have tried all suggestions which are in this thread, but none works. Could you please help me to solve it?
Thanks a lot in advance.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I have been able to fix it.
I have mapped the project with all issue types and I have add in the script the following conditional in order to remove the description field:
if (issueContext.issueType.name == "Bug") {
desc.setFormValue(defaultValue)
}else {
desc.setFormValue("")
}
Once applied it, when I choose one of my projects and select an issue type different of Bug, my description field is cleaned up.
I hope it helps.
KR.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Sir, you just made my day!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I have a questions about it:
I use this script on my jira and it works very well!
But, when I will go to edit some issues all the information in the description field desapear:
How can I solve this?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You should use getActionName() == "Create" in the condition so script won't clear the description on Edit action.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Ok, my requirement was :-
I need to set a template description for a specific Project and Issue type, and if a user chooses a different issue type, the description should remain blank.
so here's what worked for me (you can easily tweak this for your requirement)
def desc = getFieldById("description")
def defaultValue = """
* *LINE 1*
** line 1.1
* *LINE 2*
** line 2.1
"""
def des = desc.getValue();
if ((getActionName() == "Create") && (issueContext.issueType.name =="Story") &&
!desc.getValue().toString().contains("LINE 1") &&
!desc.getValue().toString().contains("LINE 2")){
desc.setFormValue(defaultValue)
}
desc =getFieldById("description")
des=desc.getValue();
if(issueContext.issueType.name !="Story" &&
desc.getValue().toString().contains("LINE 1") &&
desc.getValue().toString().contains("LINE 2")){
desc.setFormValue(" ");
}
And need to map it to *All fields*
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.