Power Scripts DC: How to hide Tempo work attributes in the Tempo UI?
Use case:
User adds new attributes to the work log form and wants to dynamically show or hide them using SIL.
Solution:
While there is a SIL Tempo connector, that one does not handle user-added work log attributes, just the ones that are added by default.
However, there is a workaround to solve this and it comes with Live Fields. Here we can injecting a JavaScript using https://appfire.atlassian.net/wiki/spaces/PSJ/pages/15480977 routine.
The main script can looks like this: which will first validate if the screen in context is the Tempo work log. And if so, then it’ll run the JavaScript
if (argv["screen"] == "tempo-log-time"){
lfHide("tempoPeriod");
lfExecuteJS("Tempo/removeAttributes.js");
}
The JavaScript used in this example, removeAttributes.js, can have the following logic
var onAddingScreen = document.getElementById("issuePickerInput");
var key = getIssueKey();
var index = key.indexOf("-");
var project = key.substring(0,index);
//console.log("Project: " + project);
if (onAddingScreen){
if (project == "TEM"){
AJS.$("#worklogForm > div:nth-child(10) > div:nth-child(2)").hide();
AJS.$("#worklogForm > div:nth-child(10) > div:nth-child(3)").hide();
}else if (project == "TEST"){
AJS.$("#worklogForm > div:nth-child(10) > div:nth-child(3)").hide();
}else if (project == "SR"){
AJS.$("#worklogForm > div:nth-child(10) > div:nth-child(3)").hide();
}
}else{
if (project == "TEM"){
AJS.$("#worklogForm > div:nth-child(7) > div:nth-child(2)").hide();
AJS.$("#worklogForm > div:nth-child(7) > div:nth-child(3)").hide();
}else if (project == "TEST"){
AJS.$("#worklogForm > div:nth-child(7) > div:nth-child(3)").hide();
}else if (project == "SR"){
AJS.$("#worklogForm > div:nth-child(7) > div:nth-child(3)").hide();
}
}
Note that I’m using Line 1 to get the Issue picker object. This is because the issue picker only shows up when you're adding a log time. However, when you’re editing it, it does not.
So, with that difference, we can safely select the node ID that needs to be hidden. To find those SELECTORs used, please see
https://appfire.atlassian.net/wiki/spaces/PSJ/pages/15482920
To get the project, we can use the getIssueKey() function that is available when a Jira issue is in context.
Here is a recording for your reference.