Forums

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

cron job to send custom notification to inactive users for a particulat Jira project

Binoy Francis
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
May 28, 2024

Hello All,
I am looking for a solution to send a custom notification to members in a Jira project. The function should check for users(already added in the project roles) who have not accessed the project "ABC" for the last 90 days. A custom notification should be send to these users.

I am currently using Jira Datacenter 8.20.30. I do have scriptrunner plugin but not the Automation for Jira plugin.

Any help will be much appreicated. Thank you.

1 answer

0 votes
Sudarsana G
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.
May 28, 2024

Schedule Script Execution: Schedule the script to run at regular intervals (e.g., daily) using ScriptRunner's built-in scheduler

Change the script based on your requirement also Make sure to replace the placeholder logic in the isInactive function with your actual implementation to check if a user is inactive based on their last login time.

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.security.roles.ProjectRoleManager
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.user.util.UserManager
import com.atlassian.jira.util.JiraUtils
import com.atlassian.jira.bc.project.ProjectService
import com.atlassian.jira.bc.projectroles.ProjectRoleService
import com.atlassian.jira.bc.projectroles.ProjectRoleActorService
import com.atlassian.jira.issue.search.SearchProvider
import com.atlassian.jira.issue.search.SearchResults
import com.atlassian.jira.web.bean.PagerFilter

def projectKey = "ABC"
def projectRoleName = "Developers"
def userManager = ComponentAccessor.getUserManager()
def projectRoleManager = ComponentAccessor.getComponent(ProjectRoleManager)
def projectService = ComponentAccessor.getComponent(ProjectService)
def projectRoleService = ComponentAccessor.getComponent(ProjectRoleService)
def projectRoleActorService = ComponentAccessor.getComponent(ProjectRoleActorService)
def searchProvider = ComponentAccessor.getComponent(SearchProvider)

def project = projectService.getProjectByKey(userManager.getUserByName("admin"), projectKey).getProject()

def projectRole = projectRoleManager.getProjectRole(projectRoleName)
def projectRoleId = projectRole.id

def inactiveUsers = []

def usersInRole = projectRoleActorService.getUsersInProjectRole(projectRole, project)

usersInRole.each { ProjectRoleService.UserRoleActor actor ->
def user = actor.getDescriptor().getUser()
if (user && isInactive(user)) {
inactiveUsers << user
}
}

def isInactive(ApplicationUser user) {
// Example logic:
// def lastLogin = userManager.getLastLoginTime(user)
// return lastLogin && lastLogin.before(Date() - 90)
// Replace the above example logic with your actual implementation
return true // Placeholder logic
}

return inactiveUsers

Richa Rajaram Aware August 20, 2024

Hi Sudarsana ,

Thank you for your help.

I have tried these script but getting error for

import com.atlassian.jira.bc.projectroles.ProjectRoleActorService library. It is showing unable to resolve class import com.atlassian.jira.bc.projectroles.ProjectRoleActorService

I'm using Jira Data Center 8.20.30 version. So is it supported for this version or is there any other option instead of this library?

Any help will be much appreciated. Thank you.

Richa Rajaram Aware August 22, 2024

Hello Team ,

Can you please provide any suggestions for the above comment. Actually I'm stuck here. 

Any help will be much appreciated. Thank you.

Best Regards,

Richa Aware

Suggest an answer

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

Atlassian Community Events