How to use LookupIssue to update a custom field
Asked by Adam Hasselgren:

I created a new Jira issue type called "Customer". The purpose is to store information about specific customer as well as identify who the project manager is for one.

On "Customer" I have a couple fields

* Customer (drop down ,single choice)
* Project Manager (user lookup, single choice)

On our normal stories, bugs, etc it also have the same fields.

Today I have some automation where if the "Customer" field is updated on a normal Jira ticket, it automatically updates the "Project Manager" field based upon the "Customer" field. As of right now I have an automation script per project manager where I hard code customers (which works but not a good solution).

What I would like to do is have some automation where it can reference the new "Customer" artifact and lookup the project manager attached to a particular customer. In Excel terms I'm basically looking to do a vlookup on a customer record to pull across the PM for a particular ticket. I know I need to leverage the lookupissues function just can't get it to work. Not sure if it's an issue because I have the "Customer" artifact in another project or if that shouldn't impact it.

Here is the field information

* "customfield_10109": "PM"
* "customfield_10063": "Customer"

Project Information

* Project A (all tickets)
* Project B (test project where the customer artifact is located)


Answers:
author: Stefan Salzl
body: Hi [@Adam Hasselgren](/t5/user/viewprofilepage/user-id/4940421) ,

How far did you come so far? Could you show your current automation rule? That would help the community to better understand the problem.

Best  
Stefan

comments: author: Adam Hasselgren
body: ![jira1.png](https://community.atlassian.com/t5/image/serverpage/image-id/214843i37E42EDFAE6768D7/image-size/large?v=v2&px=999 "jira1.png")![jira2.png](https://community.atlassian.com/t5/image/serverpage/image-id/214842iEE189E96C801F9E6/image-size/large?v=v2&px=999 "jira2.png")

I'm sure I'm missing something but I did verify the customer had an entry in the ticket that matched on the "Customer" artifact.


author: Stefan Salzl
body: Hi [@Adam Hasselgren](/t5/user/viewprofilepage/user-id/4940421) ,

First thing: smart values are case sensitive. So try to change to {{lookupIssues...}} (capital ?i") in your esit action.

furthermore (as the field is still a list) could you try the following in your edit action:

{{lookupIssues.PdM.value}}  

see the documentation below:  
<https://support.atlassian.com/cloud-automation/docs/examples-of-using-smart-values-with-lists/>

Please let me know if this works.

Best  
Stefan


author: Adam Hasselgren
body: Still no luck..I've included all the screenshots from each part of the automation just in case I'm completely missing something

![jira3.png](https://community.atlassian.com/t5/image/serverpage/image-id/215084i1C84DB14920F2466/image-size/large?v=v2&px=999 "jira3.png")

![jira4.png](https://community.atlassian.com/t5/image/serverpage/image-id/215086i98AB6B4DBB3AF2D9/image-size/large?v=v2&px=999 "jira4.png")![jira5.png](https://community.atlassian.com/t5/image/serverpage/image-id/215087i3579ED16E1E25321/image-size/large?v=v2&px=999 "jira5.png")![jira9.png](https://community.atlassian.com/t5/image/serverpage/image-id/215091iDC562921E2948768/image-size/large?v=v2&px=999 "jira9.png")![jira6.png](https://community.atlassian.com/t5/image/serverpage/image-id/215088i780638BD9DBE9E15/image-size/large?v=v2&px=999 "jira6.png")![jira8.png](https://community.atlassian.com/t5/image/serverpage/image-id/215090i60473A1ED9E556B7/image-size/large?v=v2&px=999 "jira8.png")


author: Stefan Salzl
body: It seems your JQL doesn't even deliver any results.

I would suggest the following:

* before your lookupIssue action add a ?audit log" action for debugging and let it just wright the value for customer field in your issue ---\> {{issue.Customer.value}}
* it should not be necessary to store this value in a variable ---\> try to use the smart value from previous point in your JQL in the lookupIssues action (instead of the variable)

Best  
Stefan


author: Adam Hasselgren
body: ![Screen Shot 2022-09-09 at 9.23.36 AM.png](https://community.atlassian.com/t5/image/serverpage/image-id/215269iA5217FE6D26A87FA/image-size/large?v=v2&px=999 "Screen Shot 2022-09-09 at 9.23.36 AM.png")![Screen Shot 2022-09-09 at 9.24.01 AM.png](https://community.atlassian.com/t5/image/serverpage/image-id/215271i055A6C156FED5312/image-size/large?v=v2&px=999 "Screen Shot 2022-09-09 at 9.24.01 AM.png")

So it looks like the PdM field is the thing giving me trouble. I need to use {{issue.PdM.displayName}} for it to work correctly so getting there. I now think I have an issue with my lookup...first issue I see is it doesn't want to display the customer from the lookup (log: Customer: {{lookupIssues.Customer}}

I did notice it can't "Validate query" as it's greyed out. Is my syntax incorrect?


author: Stefan Salzl
body: Hi [@Adam Hasselgren](/t5/user/viewprofilepage/user-id/4940421) ,

yeah as I mentioned before try to use the smart value directly in your lookupIssues.

so instead of your variable name (as shown in your last screenshot) use {{issue.Customer.value}}.

The JQL cant be validated as it uses a smart value which is resolved during runtime. This depends on the issue the rule is activated by.

You could just copy the jql and replace the smart value with a real example of one of your issues (like let's say you have Issue A and in the this issue the customer is John Smith ---\> try your jql in the normal issue search with ?John Smith" instead of you smart value)

Best  
Stefan


author: Adam Hasselgren
body: ![Screen Shot 2022-09-09 at 10.26.13 AM.png](https://community.atlassian.com/t5/image/serverpage/image-id/215287iD61CA6E22486B8A7/image-size/large?v=v2&px=999 "Screen Shot 2022-09-09 at 10.26.13 AM.png")![Screen Shot 2022-09-09 at 10.26.41 AM.png](https://community.atlassian.com/t5/image/serverpage/image-id/215288iF76CB8337318D496/image-size/large?v=v2&px=999 "Screen Shot 2022-09-09 at 10.26.41 AM.png")

So the weird thing is in my JQL I'm only specifying the project "TA" but when I look at the log it's adding another project which is "AM". Would this be my issue? I have must customer record in TA but the tickets it's looking up against is in "AM". Is there a way to modify this or do I need to move my "Customer" issue type into the "AM" project?


author: Stefan Salzl
body: It looks like your issues are located in different projets. is this correct?

In this case the rule must be configured as a multi-project or global rule. You can add another project to the scope in your rule details. All projects that are in the scope of your automation rule (so to say that are part of the processing) needs to be added.


author: Adam Hasselgren
body: I updated it to global and now I feel like we're sooooo close..It's sees the correct values, the JQL is fixed, however when it tries to update the field it says I'm inactive. It's the same custom field and I'm a valid user in both projects.

![Screen Shot 2022-09-09 at 12.47.29 PM.png](https://community.atlassian.com/t5/image/serverpage/image-id/215330i70F0878121BD7D2E/image-size/large?v=v2&px=999 "Screen Shot 2022-09-09 at 12.47.29 PM.png")

![Screen Shot 2022-09-09 at 2.40.45 PM.png](https://community.atlassian.com/t5/image/serverpage/image-id/215332iF3227D2FBFFAAE41/image-size/large?v=v2&px=999 "Screen Shot 2022-09-09 at 2.40.45 PM.png")


author: Stefan Salzl
body: Hi [@Adam Hasselgren](/t5/user/viewprofilepage/user-id/4940421)

could you try to just use lookupIssues.PdM or lookupIssues.PdM.value in your edit action?

The displayName is mainly meant for user picker fields. As far as I got your description you are getting the information/value from a select field (single choice). So in this case the result is already the expected value (from a user picker field you would get the id and to use the plain name you would use displayName).

Best  
Stefan


author: Adam Hasselgren
body: Brilliant! I just used the {{lookupIssues.PdM}} and it worked!!!!! Thank you [@Stefan Salzl](/t5/user/viewprofilepage/user-id/4616993) for all your help!!!!!


author: Stefan Salzl
body: AWESOME!!! sooo good to know you got that working.

It?s my pleasure ;)


author: Pierre Allard
body: Hello,

I'm trying to implement the same kind of logic but it seems I'm not able to retrieve

my custom field from my lookupIssue to put it in the audit log.

Here's the automation details:

![1dzdzd.png](https://community.atlassian.com/t5/image/serverpage/image-id/262382iEF744C7D2220B998/image-size/large?v=v2&px=999 "1dzdzd.png")

Here's the audit log:

![3_automation.png](https://community.atlassian.com/t5/image/serverpage/image-id/262377i9CA55014220189B2/image-size/large?v=v2&px=999 "3_automation.png")

I've no error, the rule is a success...

I've tried with and without .value but it's never working.

Any idea ?

My custom field is a URL, could it be due to a known limitation with this kind of field ?

Thanks in advance for your help !