Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Automation to create 1 issue for every found object in the correct project based on object attribute

Danilo Simic
Contributor
July 1, 2024

Hello everyone,

 

I want to create an automation rule that will do the following:

  1. Periodically check if there are Certificate objects whose expiration date is lower than 30 days
  2. For those that fit this condition I want to create a ticket with some information:
    1. The project must be the correct project (Certificates have inbound relationship with Host objects in which there is an attribute with JSM projects filled in) - I have no idea how to pull this information in a smart value or something similar so that it is dynamic for each found Certificate
    2. In an Asset field save the related Certificate
  3. Update the "Status" attribute of the related Certificate to "UNDER RENEWAL"

 

I have found this community post which helped me get started, but I got stuck quickly: 

https://community.atlassian.com/t5/Jira-Service-Management/Automation-loops-with-Assets-Objects/qaq-p/2267068

 

Now, what I did (as suggested in the post I linked) was I added a branch on AQL component with the following AQL:
objecttype = "SSL Certificates" and "Expiry Date" < now(30d) AND "Expiry Date" >= now(-1d)

This finds the correct objects which I confirmed with a log component.

 

Now my problem is how do I reference the linked "Host" object where the correct JSM project is stored in an attribute called "Related Project".

 

If anyone is wondering, our JSM structure is 1 project per client, that is why we have this attribute in Host objects.

 

Thank you!

1 answer

1 accepted

0 votes
Answer accepted
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 1, 2024

Hi @Danilo Simic

If I understand your assets structure it sounds like you have an inbound relationship on your SSL Certificates objects from objects in an object type called Hosts that contains the JSM Project relationship? If my understanding is correct you will need to add a Lookup Objects Action inside of your current Branch on AQL that retrieves the related object. It might look something like this:

 objectType = “Host" AND object HAVING outboundReferences(objectType = “SSL Certificates AND key = “{{object.key}}”)

 

You might need to adjust the AQL statement above to get the results you are looking for, here is a link to some reference material I use when writing AQL statements: https://support.atlassian.com/jira-service-management-cloud/docs/use-assets-query-language-aql/

while inside the branch you’ll be able to reference your Related project or any other attribute of your hosts object type via “LookupObject.ATTRIBUTE” in your example I think you’ll want to use  “LookupObjects.Related Project”

 

Danilo Simic
Contributor
July 2, 2024

Hello Kevin,

Your understanding is correct.

 

One concern here, if I use the lookup object as you described, will I get only the one host for the one certificate? I am asking because you are calling key = “{{object.key}}”, it should only use the 1 certificate that is currently running through the branch, correct?

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 2, 2024

Hi @Danilo Simic

Yes. Each object that is returned through your branch AQL will have the certificate retrieved by the lookupobjects action . If your end goal is to create an individual ticket for each expiring certificate you will want to have the action that creates the ticket inside the branch. I hope this helps.

 

 

Danilo Simic
Contributor
July 9, 2024

Hello,

 

I was able to find the correct objects using this method. Later I will see if 1 tickets with information from 1 object is created while running the rule for every object found.

 

Thank you!

Danilo Simic
Contributor
July 11, 2024

Hello @Kevin Patterson

 

Are you able to also help me with the following?

 

As I mentioned above, I am able to find the correct objects and get the information that I need, however I am unable to use the object smart values in order to create a ticket in the correct project (or to add some information from the object in the ticket for that matter).

 

I have this component:

1.PNG

 

When I run the rule, the smart value ({{lookupObjects.Related projects}}) finds the correct project but it is not recognized by the Create issue component.

 

Here is a screenshot from the rule audit log:

2.PNG

As you can see, the smart value correctly found the project "Admin Test" but the component shows an error.

 

Similar problem for the Summary of the ticket that I entered in the component.

 

Thank you!

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 @Danilo Simic ,

Sure, happy to help. I've run into issues before programmatically creating issues in different projects with the Create Issue Action. First I would check your {{lookupObject.Related projects}} Is the value in this field the name of the project or the project ID? I believe the value the project field is looking for is the project ID and the asset object attribute you are sending it is the Project Name. You should be able to correct this by using {{lookupObjects.Related projects.key}}.

 

If that doesn't work you might want to pivot to the Jira Restapi to create your issue. When I build these types of automation rules most of the time I end up just using the Send Web Request Action and specifying the values of the issue in JSON. your Json will look something like the below:

{
"fields": {
"project": {
"key": "{{lookupObject.Related projects.key}}"
},
"summary": "Certificate Renewal for {{lookupObjects.Name}}",
"description": "Description Test",
"issuetype": {
"id": "100XX" // Replace this with the actual issue type ID in your environment

}
}
}

Danilo Simic
Contributor
July 12, 2024

Hello @Kevin Patterson

 

{{lookupObject.Related projects.key}} did not work, but {{lookupObject.Related projects.id}} did work. So the component was looking for the project ID.

 

Final problem that I am struggling with. How can I use smart values to add the SSL Certificate object in an Asset custom field?

 

Here is an audit log screenshot of my last attempt:

1.PNG

 

The field is called "SSL Certificate", I have configured it as follows:

2.PNG

The field works as intended when I try to manually add a SSL Certificate object.

 

The smart values I tried to add were these (result was the same):

  1. {{lookupObjects.key}}
  2. {{lookupObjects.name}}
  3. {{lookupObjects}}

 

I did pay attention not to look at the Business Service, so in order to do this I created a variable which would save one of the 3 smart values I mentioned above.

3.PNG

4.PNG

 

If this is not possible I think I will have to use the Send web request component instead of the Create issue component.

Danilo Simic
Contributor
July 12, 2024

Apologies, one more problem that I forgot to mention.

 

If I have more than 1 related projects, how can I only pick the first one from the list?

 

5.PNG

 

In this case I have 2 related projects, AD (Admin Test) and DEMO (Demo project). Is it possible to somehow pick only the first one from the list?

Danilo Simic
Contributor
July 12, 2024

I solved the problem with adding the object in an asset field during issue creation.

 

The smart values are ok. I was just being stupid with the screens. I added "SSL Certificates" fields in the request type but it never occurred to me to add it to the create screen of the relevant issue type.

 

The problem when there are multiple projects still remains though.

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 12, 2024

For your issue with multiple projects, you might be able to  retrieve the project you want with the get method. 

I've used get to return a specific object in a list before, but i've never tried using it to retrieve a specific value from an list of attributes of the object. my best guess is the syntax will be something like this:

{{lookupObjects.Related projects.id.get(0)}} 

Danilo Simic
Contributor
July 15, 2024

Funny, {{lookupObjects.Related projects.id.get(0)}}  gets me the entire list.

While {{lookupObjects.Related projects.id.get(1)}} gets nothing.

 

I will try to figure it out. Please let me know if you have any other ideas. You have been of massive help, I do not thing I would have managed to do this much without you, thank you!

Danilo Simic
Contributor
July 15, 2024

Ok, it is very stupid for some reason.

 

{{lookupObjects.first.Related projects.id.first}} 

This works. ChatGPT suggested this, it sounded like nonsense to me but I gave it a shot, what the hell and it worked.

 

@Kevin Patterson thank you for all of your help, could not have done it without you!

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 15, 2024

No Worries, glad I was able to help. This is the first time I'm seeing ".first" used as a method, I don't recall seeing that in the AQL documentation provided by Atlassian. I'll have to do some of my own research to see what other methods work but are not documented. Thank you for sharing your lookupObjects string with the community! 

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
PREMIUM
PERMISSIONS LEVEL
Product Admin
TAGS
AUG Leaders

Atlassian Community Events