Forums

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

Writing an if statement in scriptrunner that has custom fields

Louis Andrews February 1, 2022

I am trying to write a complex condition (if statement) in scriptrunner for a custom field that is an issue type to check the value of another custom field, then transition that issue. Then if all the issues equal the same status then it will transition another issue type to another status. This will use 2 workflows that talk to each other. Example below

I have enough coding experience to know that this doable but the custom fields and transitions are confusing me with JIRA

So for an example:
issue type 1 - dealership (customField)

issue type 2 - manager (customField)

field - car (customField)

options in car - "in stock" ,"out of stock" , "preorder" 

issue status (1) - Search

issue status (1) - Add to cart

issue status (1) - Buy

issue status (2) - Sold out

1s go with issue type 1 & 2s go with issue type 2


Problem 

When status goes from, "search" to "add to cart", check if in "dealership" that "car" has the value "in stock". If value = "in stock", then transition "dealership" status to "buy". If all dealership's status is buy then transition "manager" to "sold out"

Logic

When status search transitions to  add to cart

Then for dealership 

      if car = in stock

Then status transitions to buy 

If all dealership status = buy 

    then transition manager to sold out status

 

  •  I italicized all the logical statements  
  • Bolded all the transitions
  • Underlined all the custom fields

 I tried this multiple times with automations but nested for if statements aren't possible. I may can do this with 2 automations at the same time but I get errors. 

Feel free to ask questions for more details because I am aware of the complexity. The getting the value/status of custom fields stomped me.

Please help.  

1 answer

0 votes
Tim Perrault
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 1, 2022

Hi @Louis Andrews 

Having it be two different issues makes this extremely complex. At first I thought maybe a listener, but again the two different issues.

I have a couple of questions, do the issues use the same workflow? Is one of the issues a subtask of the other? I will probably have more questions, but this will be a good start.

Thanks,

Tim

Louis Andrews February 2, 2022

Hi @Tim Perrault so I will answer your question in parts to give more detailed answers. 

- "do the issues use the same workflow?" 

  • No issues with (1) beside them is one workflow and issues with (2) beside them is another. 
  • I have been able to talk to both work flows previously through automation by transitions and having unique issue status names. 
  • Automation doesn't work for this scenario because Jira doesn't allow you to have "for" inside of another "for".  

- "Is one of the issues a subtask of the other?"

  • So this issues are not subtask of each other but they are linked. For this example: issue manager is linked to dealership by "sells car" and vice versa dealership is linked to manger by "has car" 
  • The manager is linked to dealership because the manger sells the cars of the dealership. 
  • The dealership is linked to manager because the dealership has the cars for the manager. 
  • So workflow (1) would be inventory and workflow (2) would be sells.  

I hope this helps, feel free to ask more questions to understand. I'm looking to have 2 automations that happen one after another to make this doable.

Suggest an answer

Log in or Sign up to answer