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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Scriptrunner Condtion to check user URL is homepage

I have a Scriptrunner fragment, which is supposed to run when certain conditions are met. One of the condition is to check if user URL is the homepage . I have the below code, but for some reason it doesn't work. But it does work for the date logic alone, and not when combined with the user URL . Can anyone please validate if its right.

 

def webActionSupport = ComponentAccessor.getComponent(JiraWebActionSupport)
def requestURL = webActionSupport.getHttpRequest().getRequestURI()

def homepageURL = "my homepageURL"

//Logic defined at end of script

if ((requestURL == homepageURL) && (today>=start && today<=end)) {
log1.info("Success:")
return true
}
}
return false

 

1 answer

@Antoine Berry  The requirement was like, we need to have a dialog pop up box at the time of maintenance. When the user logs in, the box must pop up. Also, the time when this must show up must be controlled from a service desk. 

We were able to actually achieve this. The dates for when the box shows up is done through two custom field vales "Start date & end date". 

But the problem I have is, the box shows up every time the page loads. More like a nuisance at this point. I want the pop up box to be limited to once per user in a day, or maybe ONLY at the log in page or something. 

I know you are AMAZING at coding, so abt script fragment, it works more like "if this condition works" then show this :):)

Below is the working code we have,

def log1 = Logger.getLogger("condition");
log1.setLevel(Level.DEBUG);

def searchService = ComponentAccessor.getComponent(SearchService)
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser();
def issueManager = ComponentAccessor.getIssueManager()
def searchRequestManager = ComponentAccessor.getComponent(SearchRequestManager)
def filter = searchRequestManager.getSearchRequestById(88201)
def query = filter.query

def search = searchService.search(user, query, PagerFilter.getUnlimitedFilter())

int counter = 0

log1.info("search 1:"+search.total)

if(search.total>1 || search.total==0)
{
return
}

else
{

def issu = search.results.get(0)

log1.info("issue 1:"+issu.getKey())
 

def customFieldManager = ComponentAccessor.getCustomFieldManager()
def startdate = customFieldManager.getCustomFieldObjectByName("Announcement Start")
def enddate = customFieldManager.getCustomFieldObjectByName("Announcement End")
def announcement = customFieldManager.getCustomFieldObjectByName("Announcement Type")

def start =(Date) issu.getCustomFieldValue(startdate)
def end = (Date) issu.getCustomFieldValue(enddate)
def Description = issu.description;
def announcementType = issu.getCustomFieldValue(announcement)
def today = new Date();
log1.info("today 1:"+today)
log1.info("start 1:"+start)
log1.info("end 1:"+end)
log1.info("type"+ announcementType)


String newInfoTag = "Jira Outage Message Once"

return true

def userPropertyManager = ComponentAccessor.getOSGiComponentInstanceOfType(UserPropertyManager.class);
def userProperty = userPropertyManager.getPropertySet(user)?.getString("Outage Box2");
if ((userProperty != newInfoTag) && (today>=start && today<=end))
{
return true
}
}
return false

 

REST END POINT:

import javax.servlet.http.HttpServletRequest
import com.atlassian.jira.user.UserPropertyManager
import com.atlassian.jira.component.ComponentAccessor
import com.onresolve.scriptrunner.runner.rest.common.CustomEndpointDelegate
import groovy.json.JsonBuilder
import groovy.transform.BaseScript
import com.atlassian.sal.api.user.UserManager

import javax.ws.rs.core.Response

@BaseScript CustomEndpointDelegate delegate

setUserProperties(
httpMethod: "GET"
) { queryParams, body, HttpServletRequest request ->

def userManager = ComponentAccessor.getOSGiComponentInstanceOfType(UserManager)
def userProfile = userManager.getRemoteUser(request)

if (userProfile) {
log.warn(userProfile.username + " set properties")
def user = ComponentAccessor.userManager.getUserByName(userProfile.username)

String newInfoTag = "Jira Outage Message Once"

def userPropertyManager = ComponentAccessor.getOSGiComponentInstanceOfType(UserPropertyManager.class);

userPropertyManager.getPropertySet(user).setString("Our Box1", newInfoTag)
}

return Response.ok(new JsonBuilder().toString()).build()
}

 

Suggest an answer

Log in or Sign up to answer