This is the example script as provided by TaskTop which can be found HERE
///////////////////////////////////////////////////////////////////////////////////////////////////// // // This is the Tempate JavaScript Workflow Provided by TaskTop // ///////////////////////////////////////////////////////////////////////////////////////////////////// // The HP ALM connector provides the following properties: // “USER_ID” - the user id of the logged in user // “DISPLAY_NAME” - the display name of the logged in user // “USER_GROUPS” - an array of Strings containing the groups that the user is a member of (also known as the user’s roles) // “DOMAIN” - the QC or ALM Domain to which the task belongs // “PROJECT” - the QC or ALM Project to which the task belongs // import the Arrays class from Java (optional) importClass(java.util.Arrays); // Declare the standard message type constants var MSG_INFO = 0; var MSG_WARNING = 1; var MSG_ERROR = 2; // Declare constants for the properties exposed by the QC and ALM connector var PROP_USER_ID = "USER_ID"; var PROP_DISPLAY_NAME = "DISPLAY_NAME"; var PROP_GROUPS = "USER_GROUPS"; var PROP_DOMAIN = "DOMAIN"; var PROP_PROJECT = "PROJECT"; // Declare constants for the ids of fields you are interested in var BG_ACTUAL_FIX_TIME = "BG_ACTUAL_FIX_TIME"; var BG_ESTIMATED_FIX_TIME = "BG_ESTIMATED_FIX_TIME"; var BG_REPRODUCIBLE = "BG_REPRODUCIBLE"; var BG_PRIORITY = "BG_PRIORITY"; // Declare any other constants var QA_MANAGER = "QA Manager"; function handleEditorOpened(dom) { // this is how you can get metadata from the task var taskId = dom.getTask().getTaskId(); var displayName = dom.getTask().getProperty(PROP_DISPLAY_NAME); var domain = dom.getTask().getProperty(PROP_DOMAIN); var project = dom.getTask().getProperty(PROP_PROJECT); var groupMessageSet = false; for(var i in groups) { if(groups[i] == QA_MANAGER) { dom.getTaskUi().setMessage( "You are a member of the QA Manager group", MSG_INFO); groupMessageSet = true; } } if(!groupMessageSet) { var groupsAsString = Arrays.toString(groups); dom.getTaskUi().setMessage( "Click to see your group membership", "You are a member of the following groups: " + groupsAsString, MSG_INFO); } } // get the IField objects containing the current values of the fields // the getField method returns null if the field is not present for that task var actualFixTime = dom.getTask().getField(BG_ACTUAL_FIX_TIME); var estimatedFixTime = dom.getTask().getField(BG_ESTIMATED_FIX_TIME); var reproducible = dom.getTask().getField(BG_REPRODUCIBLE); var priority = dom.getTask().getField(BG_PRIORITY); // change field visibility, values, etc. as desired if(actualFixTime != null) { actualFixTime.setVisible(false); } if(estimatedFixTime != null) { estimatedFixTime.setInt(1); estimatedFixTime.setRequired(true); } if(reproducible != null) { reproducible.setReadOnly(true); } } function handleSingleValueChanged(dom, fieldId, oldValue, newValue) { // change field visibility, values, etc. as desired if(fieldId.equals(BG_PRIORITY)) { if(newValue != null && newValue.equals("P1")) { // set a warning message in the task editor dom.getTaskUi().setMessage( "Priority P1 should only be used for critical tasks", MSG_WARNING); } } } function handleFieldChanged(dom, fieldId, oldValues, newValues) { if(!fieldId.equals(BG_PRIORITY)) { // set an information message in the task editor dom.getTaskUi().setMessage("You edited the field \"" + dom.getTask().getField(fieldId).getLabel() + "\"", MSG_INFO); } } function handleSubmit(dom, changedFieldIds) { // return false to prevent the user from submitting their changes return true; } function dispose() { // if necessary, do any needed cleanup here } ////////////////////////////////////////////////////////////////////////////////////////////////////////// //This sample script prevents a user from changing the status of a defect to “Closed” unless they are part //of the “QA Manager” group: // Declare the standard message type constants var MSG_INFO = 0; var MSG_WARNING = 1; var MSG_ERROR = 2; // Declare constants for the properties exposed by the QC and ALM connector var PROP_USER_ID = "USER_ID"; var PROP_DISPLAY_NAME = "DISPLAY_NAME"; var PROP_GROUPS = "USER_GROUPS"; var PROP_DOMAIN = "DOMAIN"; var PROP_PROJECT = "PROJECT"; var BG_STATUS = "BG_STATUS"; var CLOSED = "Closed"; var DEFECT = "Defect"; var QA_MANAGER = "QA Manager"; function handleSingleValueChanged(dom, fieldId, oldValue, newValue) { // warn the user when they try to make an illegal change var task = dom.getTask(); if(task.getTaskType() == DEFECT && fieldId == BG_STATUS && newValue.getString() == CLOSED) { if(!isUserQAManager(dom)) { dom.getTaskUi().setMessage("Only a QA Manager can close a defect.", MSG_ERROR); return; } } dom.getTaskUi().clearMessage(); } function handleSubmit(dom, changedFieldIds) { // prevent the user from submitting an illegal change var task = dom.getTask(); var statusField = task.getField(BG_STATUS); if(task.getTaskType() == DEFECT && statusField.getString() == CLOSED) { for(var i in changedFieldIds) { var changedFieldId = changedFieldIds[i]; if(changedFieldId == BG_STATUS) { // the status field has been changed if(!isUserQAManager(dom)) { dom.getTaskUi().setMessage( "Submit disallowed: only a QA Manager can close a defect.", MSG_ERROR); return false; // block the submission } } } } return true;// allow the submission } function isUserQAManager(dom) { var groups = dom.getTask().getProperty(PROP_GROUPS); for(var i in groups) { if(groups[i] == QA_MANAGER) { return true; } } return false; }