I have a scripted behavior that is set (on FieldA and FieldB) and works correctly. Here is the logic:
IF FieldA or FieldB is populated, then make FieldC required.
This logic works, but I am trying to put an additional behaviour in place(on FieldC) that says
"IF FieldC is updated back to "None" (Default) after it is made required, check to see if FieldA or FieldB is populated. If neither is populated, clear error and make FieldC no longer required. If either is populated, throw original error on FieldC again"
Here is how I have written the serverside script for the behaviour, but it is not working. Can anyone help guide me to the correct scripting?
{code}
def FieldAValue= FieldAField?.getValue() as String
def FieldBValue = FieldBField?.getValue() as String
def FieldCValue = FieldCField?.getValue() as String
if ((FieldCValue == "None" && FieldAValue) || (FieldCValue == "None" && FieldBValue ))
{
FieldCField.setRequired(true)
FieldCField.setError("Please make a selection other than 'None'")
}
else
{
FieldCField.setRequired(false)
FieldCField.clearError()
}
{code}
Hello,
I've been able to get this script to work as you described, let me know if you still have trouble with it. :)
def FieldA = getFieldByName("TextFieldA")
def FieldB = getFieldByName("TextFieldB")
def FieldC = getFieldByName("SelectListA")
def FieldAValue = FieldA.getValue() as String
def FieldBValue = FieldB.getValue() as String
def FieldCValue = FieldC.getValue() as String
if((!FieldCValue && FieldAValue) || (!FieldCValue && FieldBValue)){
FieldC.setRequired(true)
FieldC.setError("Please make a selection other than 'None'.")
}
else{
FieldC.setRequired(false)
FieldC.clearError()
}
Thanks @Jenna Davis,
It works fine if I select a value in FieldA or FieldB (it makes FieldC required), but if I leave FieldA or FieldB populated and update FieldC to "none", it does not throw the error on Field C again. I am trying to account for all possible combination of clicks within the form, and this is the only one left that fails.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Ahh, I see.
You'll need to add additional scripts like this onto both FieldA and FieldB in order to achieve that.
def FieldA = getFieldByName("TextFieldA")
def FieldC = getFieldByName("SelectListA")
def FieldAValue = FieldA.getValue() as String
def FieldCValue = FieldC.getValue() as String
if(FieldAValue && !FieldCValue){
FieldC.setRequired(true)
FieldC.setError("Please make a selection other than 'None'.")
}
else{
FieldC.setRequired(false)
FieldC.clearError()
}
This is because the first behaviour, on FieldC, won't recalculate when you update FieldA or Field B, it will only run when FieldC changes.
Let me know if this fixes the issue or if you have any more questions. :)
Jenna
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks @Jenna Davis, But just to be clear, I am wanting it to recalculate when FieldC is updated from any value to NULL/None (while FieldA or FieldB are still populated). The action on FieldC should drive this specific action. But here is the script I have on Field A:
{code}
def launchtypeField = getFieldByName("Launch Type")
def affiliateMID = getFieldById(getFieldChanged())
def formTracking = getFieldByName("Affiliate Tracking Method")
def displayMIDField = getFieldByName("Parent DIsplay MID")
def custReportingField = getFieldByName("Customer Status Reporting")
def parentMIDField = getFieldById("customfield_19266")
def affiliateMIDValue = affiliateMID?.getValue() as String
def formTrackingValue = formTracking?.getValue() as String
def parentMIDValue = parentMIDField?.getValue() as String
def custReportingValue = custReportingField?.getValue() as String
if (affiliateMIDValue != "" && !formTrackingValue)
{
formTracking.setRequired(true)
formTracking.setError("As Affiliate is selected as a launch type, please provide the client's Affiliate Tracking Method")
}
else {
formTracking.setRequired(false)
formTracking.clearError()
}
if (affiliateMIDValue && !custReportingValue)
{
custReportingField.setRequired(true)
custReportingField.setError("Since you populated an Affiliate MID and/or Display MID please select a customer status reporting option for those conversion tags")
}
else {
custReportingField.setRequired(false)
custReportingField.clearError()
}
if (affiliateMID.getValue() != "")
{
affiliateMID.setRequired(false)
affiliateMID.clearError()
}
{code}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Okay, in that case you shouldn't need the scripts on FieldA or B. However, the first script should work for what you're describing, I've tested it out myself.
Here's the behaviour I see when using the only first script I posted that should go on FieldC, let me know if you're wanting something different that I'm not understanding.
Now, with my second script included (on FieldA and FieldB) you'll also have this added behavior.
After your last post I'm thinking the second script I sent isn't what you want, but I believe using just the first script works as you've described. Please correct me if I'm wrong in what I'm understanding. Also, send me what you're currently using on FieldC so I can try out what you've got. :)
Jenna
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hey @Jenna Davis - You are close. Hopefully this is better description:
I hope that makes sense. I still need the scripts on FieldA and FieldB as those are what make field C required, but I need the error to pop back up if FieldC is updated (after a selection is made) and changed back to the default "none".
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Can you please send me the script you're using on FieldC so I can see exactly what you're doing? I was able to get this behavior using the first script I'd sent, I believe the second bullet point I made mentioned this. I could've made my explanation a bit clearer there, my apologies.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Jenna Davis - Sure!
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.onresolve.jira.groovy.user.FieldBehaviours
import com.onresolve.jira.groovy.user.FormField
def customFieldManager = ComponentAccessor.customFieldManager
def optionsManager = ComponentAccessor.optionsManager
def parentMIDField = getFieldById("customfield_19266")
def custReportingField = getFieldById("customfield_19579")
def affiliateMIDField = getFieldById("customfield_19264")
def affiliateMIDValue = affiliateMIDField?.getValue() as String
def parentMIDValue = parentMIDField?.getValue() as String
def custReportingValue = custReportingField?.getValue() as String
if ((custReportingValue == "None" && affiliateMIDValue) || (custReportingValue == "None" && parentMIDValue))
{
custReportingField.setRequired(true)
custReportingField.setError("please select a customer status reporting option for those conversion tags")
}
else
{
custReportingField.setRequired(false)
custReportingField.clearError()
}
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.