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

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Is it possible to get UserAgent Info from the url of the issue ?

I am trying to get the userAgent info of an issue from the issue URL to se which browser the issue is opened in  ,which i have failed to do so . So i was wondering if there is any way we can find the value. Something which can help 

import com.atlassian.jira.issue.Issue
import org.springframework.web.context.request.RequestContextHolder
import org.springframework.web.context.request.RequestContextListener
import com.atlassian.jira.plugin.webfragment.model.JiraHelper
import com.atlassian.jira.web.action.JiraWebActionSupport
import com.atlassian.jira.util.UserAgentUtil.BrowserFamily
import com.atlassian.jira.util.UserAgentUtil.Browser
import com.atlassian.jira.util.UserAgentUtil
import javax.servlet.http.HttpSession
import com.atlassian.jira.web.action.JiraWebActionSupport
import com.atlassian.jira.util.UserAgentUtilImpl
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.util.UserAgentUtil.UserAgent
import com.atlassian.jira.config.properties.APKeys
import com.atlassian.jira.web.ServletContextProvider

 

def w = issue as Issue

def Q= ComponentAccessor.getApplicationProperties().getString(APKeys.JIRA_BASEURL)

def issueUrl = "$Q/browse/$w.key"
def A= ComponentAccessor.getApplicationProperties().getString(Q)
log.warn(issueUrl)
String R = issueUrl.toString()

def L=BrowserFamily.CHROME

String d=ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser().getUsername()
JiraHelper jiraHelper = new JiraHelper()
def url = jiraHelper.getRequest()
def HTS = issueUrl.getProperties()
log.warn(HTS)

 

UserAgentUtil.UserAgent n = new UserAgentUtilImpl().getUserAgentInfo(R)
log.warn(n)

image.png

1 answer

1 accepted

1 vote
Answer accepted

Hi Faisal,

You won't find the user-agent information in the URL, but it is available in the HTTP request (when that is present):

import webwork.action.ActionContext

def userAgent = ActionContext.request?.getHeader("User-Agent")

Note that this will give you a string, which you will then have to parse yourself if you want to extract any specific data from it. If this code runs outside of the context of an HTTP request, userAgent will be null.

 

Joanna Choules, Adaptavist Product Support

Thanks @Joanna Choules  for your Reply . Currently i am running the jira instance on my personal Pc , So is it possible to get the HTTP request info .

 

I am new to the development side of it so can you help me out here . 

Some thing which will help me get the HTTP Request info 

As you said currently i am getting null

 

Thanks in advance 

Hi Faisal,

Jira still uses HTTP even if you're running it locally, so that shouldn't be a problem.

What is the context in which you're trying to get this data? I tried my code inside a script field, and it worked the way I expected it to. Are you getting null with your code, with mine, or with both?

Joanna

Thanks for the update 

@Joanna Choules 

Currently i have created scripted field which returns free  text searcher as the value for the field and i am running the code  on a particular issue and there  i am getting null for the user agent .  so i was thinking that i need to capture the HTTP request through something . Looks like there is something which i am not understanding or missing can you please help me out here 

1234.PNG

Capture1.PNG

Hi Faisal,

I just tested it locally, and it appears that this code doesn't work in Preview mode, but when you view an issue normally, it should show you the user agent string for the browser you're using. Could you try that and let me know? Do bear in mind, of course, that the value you want the field to have should be the return value of the script: if you end your code with a logging statement, the implicit return value will be null, and the field will have no value.

Joanna

Thanks @Joanna Choules . I have got the output as required and once again thanks for the help . 

 

i am getting the info for the firefox browser and also the chrome browser but when i use edge browser the user agent value is coming out as chrome browser is there any problem with the value set for it @Joanna Choules  can you please help 

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Jira

Announcing the waitlist for Jira Work Management

Hey there Cloud Community members! We’re excited to give you the first glimpse of the new home for business teams on Jira — Jira Work Management. Jira Work Management is the next generation of J...

637 views 10 16
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you