Hello,
I have a script fragment, which shows a prompt (dialog box) to the users. Currently, the script works fine, but it shows the prompt everytime the page loads. How do I limit this to once per user,/ or only at the time of login. Below is a snippet from the code,
def searchService = ComponentAccessor.getComponent(SearchService)
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser();
def issueManager = ComponentAccessor.getIssueManager()
def searchRequestManager = ComponentAccessor.getComponent(SearchRequestManager)
def filter = searchRequestManager.getSearchRequestById(3737)
def query = filter.query
def search = searchService.search(user, query, PagerFilter.getUnlimitedFilter())
How do I limit this to once per user
You can create a user property to store kind of a boolean value in it to know in your script if the dialog has been shown to that user or not (and then reset it every night or so by a job if needed).
@Hauke Bruno Wollentin Thank you for the comment.
Actually, the time for when the script must run is triggered through custom field values from a service desk. The script gets the announcement start & end date from the ticket & shows the pop up box during that specific time. It is working fine. Only issue is, the pop up shows every time the page refreshed.
Could you please help with any links or examples on how to create the user property. I do not have an extensive scripting knowledge to fully understand how to do that on my own.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
There is an example in the Adaptavist library: https://library.adaptavist.com/entity/jira-user-properties
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
If you're running ScriptRunner 7.11.0 or above, our HAPI feature provides simplified scripting syntax for many things, including reading/setting user properties: https://docs.adaptavist.com/sr4js/latest/hapi/work-with-issue-and-entity-properties#reading-and-writing-user-properties
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The idea is to run your script as described in your first post but to add a key/value pair like "my.cool.dialog.displayed: true" to every user as an user property.
In your script you than can just check if the current user has such property set or not, if not -> show the dialog; if yes -> do nothing.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Okay, makes sense. I added the below code snippet, but nothing happened. Do, you think I'm missing something,
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser();
String newInfoTag = "Update"
def userPropertyManager = ComponentAccessor.getOSGiComponentInstanceOfType(UserPropertyManager.class);
def userProperty = userPropertyManager.getPropertySet(user)?.getString("Display.Outage");
//BELOW IS THE END OF SCRIPT
if ((userProperty != newInfoTag) && (today>=start && today<=end)) {
log1.info("Success:")
return true
}
}
return false
Tried this as well, did not work
def propertyname = "OutageBox"
def propertyvalue = "positive"
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
//below is end of Script
if ((today>=start && today<=end)) {
log1.info("Success:")
return true
}
if (user) {
def userPropertyManager = ComponentAccessor.userPropertyManager
def propertySet = userPropertyManager.getPropertySet(user).setString(propertyname,propertyvalue) as String
def isPropertySet = propertySet.contains(propertyname)
return isPropertySet
}
else {
}
}
return false
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Without having more context, this should do
def user = Users.loggedInUser
def propertySet = user.propertySet
String key = "OutageBox"
def foo = propertySet.getString(key)
if (!foo) {
// Display the stuff
propertySet.setString(key, "positive")
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.