I am struggling to extract Name and Date data out of an emailed ticket through automation and Regex
Asked by Roland Kiss:

I have used the linked resource to set up my automation

[Extract Content out of Description and Summary with Regex and Automation \| Jira \| Atlassian Documentation](https://confluence.atlassian.com/jirakb/extract-content-out-of-description-and-summary-with-regex-and-automation-1157495262.html)

My automation works well until it gets to reading the description and adding the necessary comment. I have 3 fields I would like to do this with, each its separate comment. Using the resource above I have extracted the item "ID" but I am struggling to get anything extracted of the "Date" and I only get 1 out of the 2 or in some cases more "Owner" names. I have also used regex101 to verify my expressions within the smart value string and there the results shown seem correct. Will appreciate any support, I am also able to change the sample email sent to make it easier, this will always be sent as an automated email as well, so their shouldn't be variations except in the actual values.

The smart value and regex expressions I have tried using:

{{issue.description.match(".\*ID: (\\S+).\*")}}

{{issue.description.match(".\*Owner: (\\S+).\* (\\S+).\*")}}

{{issue.description.match(".\*Date: (\\S+).\*")}}

A sample of the email sent:

ID: 1

Owner: TEST Name

Date: 23/07/2024

The return comments I get

"1005"  

"TEST"

-


Answers:
author: Alex Koxaras _Relational_
body: Hi [@Roland Kiss](/t5/user/viewprofilepage/user-id/5522382) and welcome to the community!

Try the following:

* {{issue.description.match("(ID:\\s\*\\d+)")}}
* {{issue.description.match("(.\*Owner: \\S+.\*)")}}
* {{issue.description.match("Date:\\\\s\*(\\\\d{2}/\\\\d{2}/\\\\d{4})")}}

Let me know if they worked out for you!

comments: author: Roland Kiss
body: Hello [@Alex Koxaras _Relational_](/t5/user/viewprofilepage/user-id/4150197)   

Thank you for your response, I tried what you have suggested but it seems to be including the "ID: as well as the "Owner:" portion which I do not need. I have found the below to work.  

{{issue.Description.match("\[\\n\\r\].\*ID:\\s\*(\[\^\\n\\r\]\*)")}}  
{{issue.Description.match("\[\\n\\r\].\*Owner:\\s\*(\[\^\\n\\r\]\*)")}}  
{{issue.Description.match("\[\\n\\r\].\*Date:\\s\*(\[\^\\n\\r\]\*)")}}  

Following the log action these return the exepected number, name and date that I would like. I have now found myself another problem and wanted to ask to see if you could provide guidance, here I want to create a SMART variable from these which I have done with the create variable, this works fine as if I test with the log action it is correct. What I have struggled with is to then use the SMART variable in an aql search with lookup objects. The ID essentially is a component of the "Name" attirbute I have in assets as well as its own "Ledger Number" attribute which expects an integer. I have tested the lookup objects with manually entering what I expect the output of the SMART variable to be ""Name" LIKE "TEST Stamp - 1005" which works but If I replace the "1005" with {{ID}} - my previous SMART variable - it no longer works and no objects can be found. Could you perhaps point me to some documentation or help me understand the interaction here with the AQL search that prevents me from getting my expected result?  

Here is the automation flow I am using-

![Screenshot 2024-07-24 105339.png](https://community.atlassian.com/t5/image/serverpage/image-id/337551i9BE927305C1AA103/image-size/large?v=v2&px=999 "Screenshot 2024-07-24 105339.png")


author: Alex Koxaras _Relational_
body: Hi [@Roland Kiss](/t5/user/viewprofilepage/user-id/5522382) ! I thought that you needed the ID, Owner and Date :) That's why I included them within the regex. I'm glad you found out how to get the values however :)

When creating a smart variable, all the items within the array are considered to be text. Try to use the .asNumber smart function to use the number instead: <https://support.atlassian.com/cloud-automation/docs/jira-smart-values-text-fields/#asNumber>


author: Roland Kiss
body: Hi [@Alex Koxaras _Relational_](/t5/user/viewprofilepage/user-id/4150197)   
Thank you so much, for both the regex as well as the smart function help. It worked perfectly, I have 1 (probably final) question with regards to this automation. I am looking to update an asset field at the end with one of them being an object field "Owner" I am getting an error "Attribute value is not valid on Objects" I presume it is again a similar issue as earlier where the format of the input going in isn't correct but I have been unable to find what formatting I need to do extracted "Owner" variable to make it compatible with the object attribute type.  

Thanks again in advance, your input has been very helpful!


author: Roland Kiss
body: Nevermind I was able to figure out the issue, whitespaces - I was able to fix with the .trim() function from the previous resource you provided, again thank you so much for the help!


Tags: cloud

jira-service-management

jira-service-management-cloud

jira-software