Forums

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

SOLVED: Assets Custom Field AQL Filter using conditional logic

Derek Fields _RightStar_
Community Champion
July 10, 2024

Situation

I have two Object Types: Office and User. The important attributes are:

Office:

  • Managed Offices -- this is an Object Reference to other Office objects

User:

  • Jira User -- points to the Jira User account
  • Office -- the office that the user is currently assigned to
  • Superuser -- whether the user can manage ALL offices

I have a Custom Field of Assets type called "Office" that allows the Reporter to select from a list of offices that their current Office manages. 

For example, we have five Offices (A, B, C, D, E) where A manages B and C and the Reporter is in A, then they will see in the Office drop down B and C. They won't see D or E because those offices aren't managed by A

HOWEVER, If they are a Superuser, then they see all of the offices.

Problem

I can solve the first part of the requirement, which is to show only the offices that are managed by the reporter's current office. The AQL in the Issue Filter looks like this:

ObjectType = Office AND
Object HAVING inboundReferences(ObjectType = Office AND
Object HAVING inboundReferences(ObjectType = User AND
"Jira User" = currentReporter())

This works to reference through to the Offices that are managed by the Office that the Jira User is assigned to.

However, I need a way to "turn off" this filter if the user is a Superuser, in which case, they need to see all of the offices. 

I tried this version

 

ObjectType = Office AND
(Object HAVING inboundReferences(ObjectType = Office AND
Object HAVING inboundReferences(ObjectType = User AND
"Jira User" = currentReporter()))
OR
(ObjectType = User and "Jira User" = currentReporter() AND Superuser = true)

 

This didn't work, which I assume is because I am trying to return two different object types.

Is there are way to accomplish this in AQL?

1 answer

0 votes
Kevin Patterson
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.
July 11, 2024

Hi @Derek Fields _RightStar_ ,

I'm not 100% sure this can be done with AQL alone, but give this a try and let me know:

ObjectType = Office AND
(Object HAVING inboundReferences(ObjectType = Office AND
Object HAVING inboundReferences(ObjectType = User AND
"Jira User" = currentReporter()))

OR

ObjectType = "Office" AND currentReporter() in (objectType = "User" AND "Jira User" = currentReporter() AND Superuser = true)
Derek Fields _RightStar_
Community Champion
July 11, 2024

Thanks for jumping in. However, the syntax that you provided isn't legal. You can't embed an AQL within the (). It requires specifying it as an Object Having [in|out]boundReferences. 

At this point, I think that my only option is to create two Custom Fields. One that limits the selection and one that doesn't limit the selection. I will use a behavior to show the right field depending on the user's setting.

Like Kevin Patterson likes this
gyorgy_rauf November 5, 2024

Hi @Derek Fields _RightStar_

I believe the condition is working but since you already have AND operators, you need to but them in brackets.

I would try this way:

(ObjectType = Office AND (Object HAVING inboundReferences(ObjectType = Office AND Object HAVING inboundReferences(ObjectType = User AND "Jira User" = currentReporter()))) OR (ObjectType = "Office" AND Object HAVING inR(objectType = "User" AND "Jira User" = currentReporter() AND Superuser = true))

You can also use inR() and outR() instead of the long format. :)

Derek Fields _RightStar_
Community Champion
November 6, 2024

@gyorgy_rauf Thanks for reaching out. I was ultimately able to get this working. I appreciate you jumping in after all this time to help.

Like gyorgy_rauf likes this
Kevin Munz March 21, 2025

@Derek Fields _RightStar_ could you please elaborate on your solution? This would be interesting to know for our use case. Thanks in advance

Derek Fields _RightStar_
Community Champion
March 21, 2025

@Kevin Munz - Unfortunately, I no longer have access to the customer site where I implemented this and I don't remember the specific solution that I implemented. My recollection is that I created two different fields and then showed the one appropriate to the user. This was on Data Center where I had access to ScriptRunner behaviors that allowed me to do a lot of dynamic form handling.

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
PRODUCT PLAN
STANDARD
TAGS
AUG Leaders

Atlassian Community Events