Forums

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

How to send email to user in an asset field using groovy/scriptrunner

Va man January 6, 2025

Hi everyone,

 

I have an asset Object schemas that is here to list users workstations

This object schema have computers objects. 

Those computers objects are compsoed of :

- a simple text field (Type default, Type value text) "name"

- a user picker field (Type User, no Type value) called "owner", to associate computer to his owner

- a certificate expiry date in a date field (Type Default, type value Date)called "expiry date"

 

I created a script to list every month all computers that will expire in next 45 days. 

This script then create a ticket and list all objects Computer and show their Name and Expiry date

This part works well

Now, they asked me to send an email to the owner to inform him that his certificate will expire, so it makes for easier tracking and organizing

 

I thought it would be as easy as getting the other infos but I'm here because it wasn't

Online ressources I found did not worked in my case

 

I tried to get the Owner name showing, or at least it's email

I tried something like below

=================

 

 

def query = '"Expiry date" < now(45d)'

Assets.search(query).each {
    log.warn(it.getString('Owner'))
    expiringAssets += "=========\n"
    expiringAssets += "Computer Name " + it.getName() + "\n"
    expiringAssets += "Expiry date: " + it.getAttributeValues("Expiry date")[0].dateValue.format("dd/MM/yyyy") + "\n"
    expiringAssets += "\n\n"
}
==================
It works for Name and Expiry Date, but the log.warn gives me a value like below
2025-01-06T16:33:36,023 WARN [runner.ScriptBindingsManager]: JIRAUSER12618

 

I can do nothing with this JIRAUSER12618 value. I tried to access value using it.getAttributeValues but it failed too.

 

DO you have any idea on how to get the user values from this field and then being able to send an email to him ? Even using the UserManager only sent me to a dead end avec the JIRAUSER value seems not to be an username value, and jsut some itnernal value that I did not found how to use

 

Regards,

0 answers

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events