Hello,
Using in post function, i would like to use the cascading field, and if both is matching, i would like to set a customfield value?
is there a way to do this?
i tried by the following code:
import com.atlassian.jira.ComponentManager import com.atlassian.jira.issue.CustomFieldManager import com.atlassian.jira.issue.MutableIssue import com.atlassian.jira.issue.customfields.view.CustomFieldParams import com.atlassian.jira.issue.fields.CustomField ComponentManager componentManager = ComponentManager.getInstance() CustomFieldManager customFieldManager = componentManager.getCustomFieldManager() MutableIssue issue = componentManager.getIssueManager().getIssueObject('TP-7') def stringval = "123" if (cfValues['Select Email Template']?.values()*.value == ['Privacy', 'ID Check']) issue.setCustomFieldValue(customFieldManager.getCustomFieldObject(10806), stringval) else null
But doesnt seem to work, any solution?
Many thanks for your help,
Pon
For cascade fields HashMap<String, String> is returned. Try this code
import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.issue.CustomFieldManager import com.atlassian.jira.issue.MutableIssue MutableIssue issue = ComponentAccessor.getIssueManager().getIssueObject('TP-7') CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager() HashMap<String, String > value = (HashMap<Object, Object>) issue.getCustomFieldValue(customFieldManager.getCustomFieldObjectByName("Select Email Template")); if((value.get(null).equals("Privacy") && (value.get("1").equals("ID Check")))){ issue.setCustomFieldValue(customFieldManager.getCustomFieldObject(10806), stringval) }
@Vasiliy Zverev Thanks you so much!
I placed the below code into postfunction but the customfield 10806 is not populating, am i doing something wrong?
import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.issue.CustomFieldManager import com.atlassian.jira.issue.MutableIssue CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager() HashMap<String, String > value = (HashMap<Object, Object>) issue.getCustomFieldValue(customFieldManager.getCustomFieldObjectByName("Select Email Template")); if((value.get(null).equals("Privacy") && (value.get("1").equals("ID Check")))){ issue.setCustomFieldValue(customFieldManager.getCustomFieldObject(10806), "123") }
using JIRA 6.3.3
Many thanks,
Pon
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Try to debug it using Script console.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks @Vasiliy Zverev. i ran it by scrip console, seems to be fine (no errors) but when i run it in post function, comment // on mutable issue, email body isnt populate, is there a way i should try to debug this?
import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.issue.CustomFieldManager import com.atlassian.jira.issue.MutableIssue //MutableIssue issue = ComponentAccessor.getIssueManager().getIssueObject('TEST-422') CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager() HashMap<String, String > value = (HashMap<Object, Object>) issue.getCustomFieldValue(customFieldManager.getCustomFieldObject(11401)); def stringval = "123" if((value.get(null).equals("Privacy") && (value.get("1").equals("ID Check")))){ issue.setCustomFieldValue(customFieldManager.getCustomFieldObject(10806), stringval) }
Not sure if its how im declaring my string?
Should i be debugging this somehow?
Any suggestion please, many many thanks.
Pon
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
What type of field is customField_10806?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hey @Steven Behnke,
Thanks for your interests, customfield_10806 is a free text (Multi-line) field.
Really not sure whats causing it not to apply the value string
Many thanks,
Pon
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
To store changes into a database it is requred to call IssueManager.updateIssue() method.
import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.event.type.EventDispatchOption import com.atlassian.jira.issue.CustomFieldManager import com.atlassian.jira.issue.MutableIssue import com.atlassian.jira.issue.UpdateIssueRequest //MutableIssue issue = ComponentAccessor.getIssueManager().getIssueObject('TEST-422') CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager() HashMap<String, String > value = (HashMap<Object, Object>) issue.getCustomFieldValue(customFieldManager.getCustomFieldObject(11401)); def stringval = "123" if((value.get(null).equals("Privacy") && (value.get("1").equals("ID Check")))){ issue.setCustomFieldValue(customFieldManager.getCustomFieldObject(10806), stringval) ComponentAccessor.getIssueManager().updateIssue( ComponentAccessor.getJiraAuthenticationContext().getUser() , issue , UpdateIssueRequest.builder().eventDispatchOption(EventDispatchOption.ISSUE_UPDATED).sendMail(false).build() ) }
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you so much for your reply @Vasiliy Zverev
Unfortunately no luck, customfield (11401) "Email Body" still not updating to the string value
I've basically copied the code:
import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.event.type.EventDispatchOption import com.atlassian.jira.issue.CustomFieldManager import com.atlassian.jira.issue.UpdateIssueRequest CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager() HashMap<String, String > value = (HashMap<Object, Object>) issue.getCustomFieldValue(customFieldManager.getCustomFieldObject(11401)); def stringval = "Hello test" if((value.get(null).equals("Privacy") && (value.get("1").equals("ID Check")))){ issue.setCustomFieldValue(customFieldManager.getCustomFieldObject(10806), stringval) ComponentAccessor.getIssueManager().updateIssue( ComponentAccessor.getJiraAuthenticationContext().getUser() , issue , UpdateIssueRequest.builder().eventDispatchOption(EventDispatchOption.ISSUE_UPDATED).sendMail(false).build() ) }
and placed it as the last operation also (I've tried changes the orders as well) still no luck.
Not sure if its me, but this is the cascading field below;
select_template.JPG
I really dont know where its going wrong.
I thank you for helping me this far so much.
Regards,
Pon
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
It seems that wrong customfild id into
issue.setCustomFieldValue(customFieldManager.getCustomFieldObject(
10806
), stringval)
Replace it with correct one
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hey @Vasiliy Zverev
I've tried another customfield id, and it doesn't seem to work with that also.
I've also tried with:
customFieldManager.getCustomFieldObjectByName(
"Email Body"
)
)also doesn't work.
Do you think there is a alternate solution to this?
I ran it by the scriptconsole with no errors found
Many many thanks
Pon
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
There are two options:
To check it try to execute code into a script console. Before update add
return "before update".
Then will go further.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hey Vasiliy,
Thank you so much,
I've just tested the condition, and its returning false?
HashMap<String, String > value = (HashMap<Object, Object>) issue.getCustomFieldValue(customFieldManager.getCustomFieldObjectByName("Select Email Template")); def condition = value.get(null).equals("Privacy") && (value.get("1").equals("ID Check")) return condition
Also check with only:
def condition = value.get(null).equals("Privacy")
and its returning false aswell?
Any solution?
Many Many thanks,
Pon
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I GOT IT WORKING
Thanks Vasiliy.
Below code works for me, but only checks for second value,it can be amended to check for first value aswell:
import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.event.type.EventDispatchOption import com.atlassian.jira.issue.CustomFieldManager import com.atlassian.jira.issue.UpdateIssueRequest import com.atlassian.jira.issue.MutableIssue import com.atlassian.jira.issue.fields.CustomField MutableIssue issue = ComponentAccessor.getIssueManager().getIssueObject('TEST-422') CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager() //HashMap<String,String > value = (HashMap< String, String>) issue.getCustomFieldValue(customFieldManager.getCustomFieldObject(11401)); value = issue.getCustomFieldValue(customFieldManager.getCustomFieldObject(11401)); def stringval = "ID Check" def cascval = (String)value.get("1") if (cascval == "ID Check") issue.setCustomFieldValue(customFieldManager.getCustomFieldObject(10806), stringval) else if (cascval == "Closing") issue.setCustomFieldValue(customFieldManager.getCustomFieldObject(10806), "closing") ComponentAccessor.getIssueManager().updateIssue( ComponentAccessor.getJiraAuthenticationContext().getUser() , issue , UpdateIssueRequest.builder().eventDispatchOption(EventDispatchOption.ISSUE_UPDATED).sendMail(false).build() )
Thanks,
Pon
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.