Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

nFeed/Behaviour - How to make a field required based on a precedent field value

Florian Edian
Contributor
May 17, 2019

Hello!

I am currently using 4 nFeed fields (let's say A, B, C and D) in my request type. When a customer is selecting option 1 in the A field, I would like to be able to set field B, C and D required.

Here is what I wrote in my Behaviour:

import com.onresolve.jira.groovy.user.FormField;
import com.onresolve.jira.groovy.user.FieldBehaviours
import com.atlassian.jira.issue.priority.Priority
import groovy.transform.BaseScript

@BaseScript FieldBehaviours fieldBehaviours

FormField subLevel1Field = getFieldById("customfield_13009")
FormField subLevel2Field = getFieldById("customfield_13010")
FormField subLevel3Field = getFieldById("customfield_13011")
FormField productField = getFieldById("customfield_13008")
String[] productFieldValue = (String[]) productField.getFormValue()

if (productFieldValue[0].equals("THETRAWIN")) {
subLevel1Field.setRequired(true)
subLevel1Field.setLabel("Sous-catégorie 1 *")
subLevel2Field.setRequired(true)
subLevel2Field.setLabel("Sous-catégorie 2 *")
subLevel3Field.setRequired(true)
subLevel3Field.setLabel("Sous-catégorie 3 *")
}

else {
subLevel1Field.setRequired(false)
subLevel1Field.setLabel("Sous-catégorie 1")
subLevel2Field.setRequired(false)
subLevel2Field.setLabel("Sous-catégorie 2")
subLevel3Field.setRequired(false)
subLevel3Field.setLabel("Sous-catégorie 3")
}

Also FYI:

  • The setLabel part is working.
  • In the request type configuration, subLevel fields are set to be optional. If I set them as required, it doesn't change anything.

Thanks in advance for your help,

Florian

2 answers

0 votes
Jacek Zarzycki
Contributor
July 20, 2022

Hi Laura


What I noticed:
When the Service Desk screen is created, the Elements Connect field does not have any value - it is empty ''.
Only when I select something from the list and remove it so nothing is selected, the value

'{"inputValues":[]}' is returned and then everything start to works fine.
It looks like your field is not properly initialize and the Script runner cannot validate it.
Kind regards,
Nelly Sammak July 20, 2022

Hello @Jacek Zarzycki 

I'm Nelly and I'm part of the Support team at Elements.

Here's a sample Behaviour that is working on my side:

 

import com.onresolve.jira.groovy.user.FormField;
import groovy.json.JsonSlurper

FormField descriptionField = getFieldById("description")
FormField elementsConnectField = getFieldById("customfield_10125")//update Connect field ID
String connectFieldValue= elementsConnectField.getFormValue()
def jsonSlurper = new JsonSlurper()
def json = jsonSlurper.parseText(connectFieldValue)
def connectFieldKeys = json["inputValues"]
if (connectFieldKeys[0].equals("10814")){//update the field Key value to be checked
    descriptionField.setFormValue("AST-12 is selected");
}
else {
    descriptionField.setFormValue("AST-12 is not selected");
}  
It will check the value of a Connect field Issue Picker "customfield_10125" (the field Key is an issue id) and display a message in the Description field.
On portal side, when creating an issue, if Connect field is empty (the user didn't select any issue), no message will be displayed into the Description field, which is normal.
If the user selects the issue which its id equals "10814" (the value I checked in my condition), then the message "AST-12 is selected" will be displayed.
If the user selects another issue (the issue id doesn't equal to 10814), the message "AST-12 is not selected" will be displayed in the Description field.
As I mentioned before, the above is working on my side. Does that seems similar to what you are trying to do on your side? If not, please to share more details about your use case either here or in a ticket on our portal: https://support.elements-apps.com
Kind Regards,
Nelly
Jacek Zarzycki
Contributor
July 21, 2022

Hi Nelly
In my case it is a drop down list field.
And I have no problem reading the values.

Here is the definition

def ServerDivision = getFieldById(getFieldChanged())
def elementsConnectField = getFieldByName("My list")

elementsConnectField.setHidden(true)
elementsConnectField.setRequired(false)

if (ServerDivision.getValue().toString().contains("Division 2") ) {
elementsConnectField.setHidden(false)
elementsConnectField.setRequired(true)
}

The user selects "Division 2" in the ServerDivision field and elementsConnectField is shown on the form.

The problem is that when the user skips the elementsConnectField and clicks "Create" despite the fact that elementsConnectField.setRequired (true) is set in the behavior and there is no selected value in the field, the formula is sent anyway.

Best Regards Jacek

Nelly Sammak July 22, 2022

Hello Jacek

I'm sorry for my late reply and thank you for the additional information.

The problem you described is an identified bug in our backlog and it affects Connect version after 6.10.0

Do you have a staging instance where you can downgrade the app to version 6.9.8 and test if the problem still occurred?

Kind Regards,

Nelly

Jacek Zarzycki
Contributor
July 22, 2022

Hi Nelly

I have version 6.11.9 on Jira 8.22.6

Best regards Jacek

Nelly Sammak July 26, 2022

Hello Jacek

I'm sorry for my late reply.

I did further testing on my side and I'm afraid the only solution is downgrade to any version before 6.10.0 (I tested on 6.9.8 and it works correctly).

If further help is needed, please don't hesitate to reach out to our support at: https://support.elements-apps.com

We really apologize for the inconvinience and we thank you for your understanding.

Kind Regards,

Nelly.

0 votes
Nicolas Esteves
Contributor
May 22, 2019

Hi @Florian Edian

If the setLabel part is working fine, that means everything directly related to Elements Connect (formerly nFeed) fields is working properly. So, problem must be related to the setRequire instruction, because from what I can see, there is no problem in your script (source: https://valiantys.atlassian.net/wiki/spaces/NFEED512X/pages/266698758/ScriptRunner+Behaviours+compatibility). And in such a case, that would mean only Adaptavist could fix that.

What's the versions of your Apps?

Kind regards,

Florian Edian
Contributor
May 23, 2019

Hello Nicolas,

Thanks for your answer.

I've just updated ScriptRunner which is now 5.5.6.1 and Elements Connect to 5.13.27.

Those updates did not change anything, if you were wondering :)

Regards,

Nicolas Esteves
Contributor
May 23, 2019

Hi @Florian Edian

Can you please ask to add me in the support ticket with Adaptavist?

Kind regards,

Like Florian Edian likes this
Jacek Zarzycki
Contributor
July 19, 2022

HI

I have the same problem
I am using the versions below.

Elements Connect 6.11.8
Adaptavist ScriptRunner for JIRA 6.55.0

The situation is critical because we receive requests where the necessary information is missing.

Kind regards,

Julie d_Antin _Elements_
Atlassian Partner
July 19, 2022

Hello @Jacek Zarzycki ,

To get the best help, I would recommend raising a request with Adaptavist (like the previous poster). If the problem is not with ScriptRunner, you can raise a request with Elements at https://support.elements-apps.com

Jacek Zarzycki
Contributor
July 20, 2022

See my answer.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events