How to set the version fields of a JIRA ticket from Groovy - groovy

I'm using JIRA 7.1.4 Server and under Behaviours I'm trying to create a Groovy Initialiser Function for setting default values of form fields, so when the user tries to create a new ticket, some fields are already filled in with default values. This is what I have so far:
import com.atlassian.jira.component.ComponentAccessor
def versionManager = ComponentAccessor.getVersionManager()
def versions = versionManager.getVersionsUnreleased(issueContext.projectObject.id, false)
getFieldById("affectedVersion").setFormValue([versions.first().id])
getFieldById("description").setFormValue([versions.first().id])
When the dialog for creating a new JIRA ticket opens, this script successfully sets the "Description" field to the right version id (only for debugging purposes), but the "Affects Version/s" field remains empty for some reason.
I think the id of the "Affects Version/s" field is OK, because I got it from JQL, so e.g. the following query displays correct information:
project = "--------" and affectedVersion is EMPTY
Therefore I assume that I'm trying to set the value of the version field incorrectly, but cannot figure out the mistake. The above Groovy script is based on this example, but the script might be wrong, and I was not able to find more information about getFieldById or setFormValue here either.
Can anyone give a working example of setting JIRA's "Affects Version/s" or "Fix Version/s" fields from Groovy?

If you setting fixversion on issue create step in workflow. You need to put this script into first post function(before issue create).
import com.atlassian.jira.component.ComponentAccessor
def versionManager = ComponentAccessor.getVersionManager()
def versions = versionManager.getVersionsUnreleased(issue.getProjectObject().getId(), false)
issue.setAffectedVersions([versions.first()])

Related

How to create Jira Team using GeneralTeamService plugin in Groovy script

I am using the GeneralTeamService Plugin to get and set the Team field value in my groovy script. I have a requirement to create a team through the script. I have found the below method for Creating Team but not sure what is the input for it.
#WithPlugin("com.atlassian.teams")
#PluginModule GeneralTeamService teamService
//get Team custom field object
def cfTeam =
ComponentAccessor.customFieldManager.getCustomFieldObjectsByName('Team').first()
def user = ComponentAccessor.jiraAuthenticationContext.loggedInUser
log.debug "foundTeamId ${foundTeamId}"
issue.setCustomFieldValue(cfTeam, teamService.getTeam(foundTeamId, true).get())
issueManager.updateIssue(user, issue, EventDispatchOption.ISSUE_UPDATED, false)
// does a new team have to be created?
teamService.createTeam(teamDescription)
Here i dont get what is teamDescription variable
Also, it will be helpful if someone can provide me GeneralTeamService plugin details link.
Thanks in Advance

Navigating from Location to Workorder

I need to :
1. Create a single page location application
2. Display all the asset present in the selected location in a table
3. Provide a button from which user can navigate to WOTRACK to view all the workorder(s) created on selected location and its asset(s).
I am facing difficulty in the 3rd one. I have tried Launch in Context and it is working fine except am not able to pass sql query like 'location={location} and assetnum in ({asset.assetnum})'. I need to filter workorders with particular location and all its assets.
I tried to save all the assets in the location to a Non-persistant attribute and passing the values of the attribute in the Launch in context url, Its working as expected but to do so I have written a script on 'Initialize value' which is causing performance issues.
script goes like this:
from psdi.server import MXServer;
from psdi.mbo import MboConstants;
if app == "LOCATION1" :
if mbo.getString("LOCATION") is not None:
Locsite = mbo.getString("SITEID")
desc = mbo.getString("DESCRIPTION")
MaxuserSet = MXServer.getMXServer().getMboSet("MAXUSER", mbo.getUserInfo())
MaxuserSet.setWhere(" userid='"+user+"' ")
MaxuserSet.reset()
UserSite = MaxuserSet.getMbo(0).getString("DEFSITE")
if Locsite == UserSite:
AssetSet = mbo.getMboSet("ASSET")
AssetSet.setFlag(MboConstants.DISCARDABLE, True);
if not AssetSet.isEmpty():
AssetList = ""
AssetMbo = AssetSet.moveFirst()
while AssetMbo is not None:
AssetList = AssetList + str(AssetMbo.getString("ASSETNUM")) + "%2C"
AssetMbo = AssetSet.moveNext()
mbo.setValue("non-persitant",str(AssetList),11L)
and in the LIC url i have given : 'http://xx.x.x.xx/maximo/ui/?event=loadapp&value=wotrack&tabid=List&additionalevent=useqbe&additionaleventvalue=location={LOCATION}|assetnum={non-persistant}'
Is there any other feasible solution to the requirement?
Thanks in Advance
Launch In Context is better used for sending the user to an outside-of-Maximo application and passing along some data from inside-Maximo to provide context in that external app.
What you are doing sounds like a good place to use a workflow process with an Interaction node. The developer tells the Interaction node which app to take the user to and which Relationship to use to find the data the user should work with there.
Why don't you add a table control inside the table details (expanded table row) and show a list of the work orders there. From the WONUM in that table, you could have an app link to take them to WOTRACK, if they want more details about a particular work order. No customization (automation scripting) needed. No workflow needed. Nice and simple.

Maximo automatisation script to change statut of workorder

I have created a non-persistent attribute in my WoActivity table named VDS_COMPLETE. it is a bool that get changed by a checkbox in one of my application.
I am trying to make a automatisation script in Python to change the status of every task a work order that have been check when I save the WorkOrder.
I don't know why it isn't working but I'm pretty sure I'm close to the answer...
Do you have an idea why it isn't working? I know that I have code in comments, I have done a few experimentations...
from psdi.mbo import MboConstants
from psdi.server import MXServer
mxServer = MXServer.getMXServer()
userInfo = mxServer.getUserInfo(user)
mboSet = mxServer.getMboSet("WORKORDER")
#where1 = "wonum = :wonum"
#mboSet .setWhere(where1)
#mboSet.reset()
workorderSet = mboSet.getMbo(0).getMboSet("WOACTIVITY", "STATUS NOT IN ('FERME' , 'ANNULE' , 'COMPLETE' , 'ATTDOC')")
#where2 = "STATUS NOT IN ('FERME' , 'ANNULE' , 'COMPLETE' , 'ATTDOC')"
#workorderSet.setWhere(where2)
if workorderSet.count() > 0:
for x in range(0,workorderSet.count()):
if workorderSet.getString("VDS_COMPLETE") == 1:
workorder = workorderSet.getMbo(x)
workorder.changeStatus("COMPLETE",MXServer.getMXServer().getDate(), u"Script d'automatisation", MboConstants.NOACCESSCHECK)
workorderSet.save()
workorderSet.close()
It looks like your two biggest mistakes here are 1. trying to get your boolean field (VDS_COMPLETE) off the set (meaning off of the collection of records, like the whole table) instead of off of the MBO (meaning an actual record, one entry in the table) and 2. getting your set of data fresh from the database (via that MXServer call) which means using the previously saved data instead of getting your data set from the screen where the pending changes have actually been made (and remember that non-persistent fields do not get saved to the database).
There are some other problems with this script too, like your use of "count()" in your for loop (or even more than once at all) which is an expensive operation, and the way you are currently (though this may be a result of your debugging) not filtering the work order set before grabbing the first work order (meaning you get a random work order from the table) and then doing a dynamic relationship off of that record (instead of using a normal relationship or skipping the relationship altogether and using just a "where" clause), even though that relationship likely already exists.
Here is a Stack Overflow describing in more detail about relationships and "where" clauses in Maximo: Describe relationship in maximo 7.5
This question also has some more information about getting data from the screen versus new from the database: Adding a new row to another table using java in Maximo

Failed to add fields.Selection to parent model

I'm working on access restriction to res.partner.
Currently I have two questions:
1.Why does this code don't create new field to inherited model (first error was something like "unknown object _", now it's gone): (Now it works, first question is answered)
from odoo import models, fields
class partner(models.Model):
_inherit = 'res.partner'
privacy_visibility = fields.Selection([
('followers', _('On invitation only')),
('employees', _('Visible by all employees')),
#error was here. according to odoo documentation, here is a comma
#if you remove it, the code works: [![enter image description here][1]][1]([('',''),('',''),('','')])
],
string='Privacy', required=True,
default='employees',
help="Holds visibility of the partner that affects currently logged user:\n"
"- On invitation only: Employee may only see the followed partners\n"
"- Visible by all employees: Employee may see selected partner\n")
Later, when my restrictions would be applied, how to make selected users to access all pertners anyway? (my ideas - 1.to hide "privacy_visibility" field to be visible in developer mode only, as it made for project's "sub-task project". 2.to create a new group, but I have no idea how to use access groups with row-level access), which way wold you recommend to go?
First Question Ans:
The Selection field syntax is not correct please follow this syntax
Example:
gender = fields.Selection([('male', 'Male'), ('female', 'Female'), ('any', 'Any')], string='Gender')
You are calling the translate object (the underscore "_") to translate your selection values, but you did not import it.
Change:
from odoo import models, fields
To:
from odoo import models, fields, _

Overwrite Major Version Using Object Model

I have versioning and checkin/checkout enabled in a SharePoint 2010 list, and for business-related reasons, would like to update information in a field: overwriting the field data for all versions in a similar manner and in place so that the version numbers do not change.
If I call SPListItemVersion.ListItem.UpdateOverwriteVersion(), it fails stating that I need to check out the item before making changes to it. Makes sense. So I precede the update statement with SPListItemVersion.ListItem.CheckOut() statement, attempt the update, and receive an error that I cannot overwrite a published version. I've also attempted to precede the check out with SPSite.AllowUnsafeUpdates = true, setting it back to false after the update call, but the latter error still occurs. Any ideas?
Stripped code below:
foreach (SPListItemVersion itemVersion in item.Versions){
itemVersion.ListItem.File.CheckOut(SPFile.SPCheckOutType.Online, itemVersion.ListItem.File.TimeLastModified.ToString());
site.AllowUnsafeUpdates = true;
itemVersion.ListItem["FieldName"] = "changed value here";
itemVersion.ListItem.UpdateOverwriteVersion();
site.AllowUnsafeUpdates = false;
itemVersion.ListItem.File.CheckIn("Updated list item version", SPCheckinType.OverwriteCheckIn);
}
To anyone that may find themselves facing this issue, you do not need to toggle the AllowUnsafeUpdates field. What worked for me is replacing the itemVersion.ListItem.UpdateOverwriteVersion() statement with itemVersion.ListItem.SystemUpdate(false). The parameter passed in tells SharePoint to not create a new version when updating.
Edit: This answer only updates the current item again. SPListItemVersion field references are available via a get only; it appears this is not possible in the object model.

Resources