Forums

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

How do I use Virtucal Functions and a Conditional Statement in the IFTTT-Body to populate a field?

Manuel_vA
Contributor
July 17, 2020

Context

I update a Jira issue using a Confiforms form and the 'Confiforms IFTTT Integration Rules' box.

In my form I have two radio button fields both with the options 'yes' and 'no'.

When radio button field A is set to"Yes", I  fill a Jira custom field with some content of my form.

When radio button field B is set to "Yes" as well:

I want to append some other content of my form to that same Jira custom field.

 

I don't think I can append to a Jira custom field in the 'No Format' area directly. That's why I use a Confiforms field that I called 'IftttConstructionField' as a buffer field.

 

Basic Problem

My problem is that I can't fill that buffer field depending on my two radio button decisions by using a Conditional Statement.

I think the problem is better illustrated in my 2 approaches:

 

Approch 1 (which is probably the most promising)

I use an IF-function and the virtual function append() outside the 'No Format' area. I use a Confiforms form field called 'IftttConstructionField' to append my content to.

That field 'IftttConstructionField' I use again in the 'No Format' section where I build my json to allocate the value to the Jira custom field 'customfield_19410'.

As far as I understand it from the docs, it is possible to use virtual functions and the IF-function within the IFTTT-Body. That's why I think this could therotically work.

approach_1.PNG

 

Approach 2

My second approach tries to use the virtual function append() within the 'No Format' area. This way I don't have a problem with the Conditional Statement, but using virtual functions within the 'No format' section doesn't seem to work:

(I tried a lot small syntax changes but maybe never got it quite right)

approach_2.PNG

 

Alternatives

Of course I could solve this problem in another way. For example by simply using two Jira custom fields. 

But using Virtual Functions and IF-Statements when formating json within an IFTTT-Body is a gneral problem to me which I haven't figured out yet.

I appreciate any hints or suggestions!

 

Versions:

Confluence: 6.5.16

ConfiForms: 2.12.4

1 answer

1 accepted

1 vote
Answer accepted
Alex Medved _ConfiForms_
Community Champion
July 17, 2020

That is pretty easy actually...

You just put two [entry.field_name] references together and this is the append.

No need for any virtual function or anything

"customfield_19410":"[entry.somefield] [entry.some_other_field] And some static text can be here, why not!?"
Manuel_vA
Contributor
July 18, 2020

Hello Alex,

thanks a lot for your answer! Actually I’m using your suggestion in simpler scenarios. But in this case I include two ‘yes/no’-questions in my form that have an influence on how my Jira custom field should be populated. Naming my steps might help to clarify my problem:

  • In my form I ask my user a first yes/no question. If my user says no, I don’t update my Jira field at all. I’m done.
  • If my user says ‘yes’, I ask for field input and combine those [entry.somefield] in my ifttt-json with static text, e. g.: “customfield_19410” : “Name: [entry.somefield]\n Department: [entry.someotherfield]\n”
  • Then I ask another yes/no question. If the user answers ‘no’, I update my Jira custom field with the content I added so far. And I’m done.
  • But if my user answers ‘yes’ I want to append to the Jira customfield_19410 more static text combined with some [entry.somefield].

Because of the static content, I can’t append it like you suggested. Because this would mean that in case my user answers my second question with ‘no’, I have static text in my Jira customfield that I don't want. That’s the reason why I work with conditional statements and virtual functions here.

Alex Medved _ConfiForms_
Community Champion
July 18, 2020

Sorry, I am confused... still unsure why you need a virtual function of any kind here

What you need is just a Velocity #if #end statements to define and collect information into the "Velocity" template variables

 

I will give you an example how you can "collect" values into the Velocity defined field and then use it's value in the JSON

 

Below, I have a form with 2 radio fields (r1 and r2, each having 2 choices 1 and 2)

See how I can format the "description" field based on the choices my user makes on the form

Screenshot 2020-07-18 at 13.08.11.png

No virtual functions... just pure Velocity templating 

Like Christopher Lanphear likes this
Manuel_vA
Contributor
July 18, 2020

Hello Alex,

with your last sample code, you completely solved my problem! Thanks a lot. Great help!

I tried that approach before but I was incapable of simply using the $desc variable again on the right side of the variable assignment like you did it for example in this line:

#set($desc = "$!{desc} [entry.r2.label]")

(I didn't necessarily want to solve this by using virtual functions, but it was the only idea I had left..)

Maybe I should rewrite my headline question to avoid confusing other community users who stumble over this?

Gustavo Ortega Reynoso
Contributor
August 10, 2023

 

@Alex Medved _ConfiForms_ 

I have a little issue, I have my confi but I need to evaluate the value of a combo in the form and based on that value define the label that I will send to the jira task, I have this:

confi if.pngbut it shows an error in the line marked in blue

Thanks a lot!!!

Alex Medved _ConfiForms_
Community Champion
August 10, 2023

I think labels field in Jira expects an array (JSON array)

Gustavo Ortega Reynoso
Contributor
August 15, 2023

 

Its working!!!

 

Thanks a lot dear @Alex Medved _ConfiForms_ 

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events