Conditional script is not blocking save when logged-in user is retrieved
I created the below Read-Only Conditional script and applied it on Status attribute. It does not block the save operation saying 'State is not modifiable'.
Any fix?
dojo.require("com.ibm.team.repository.web.client.session.Session");
(function() {
dojo.declare("com.example.ConditionalScript01", null, {
matches: function(workItem, configuration) {
var getAuthenticatedContributor = com.ibm.team.repository.web.client.session.getAuthenticatedContributor;
var loggedInUsername = getAuthenticatedContributor().name;
return true;
}
});
})();
|
3 answers
Ralph Schoon (63.5k●3●36●46)
| answered Dec 13 '21, 2:46 p.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER edited Dec 13 '21, 2:47 p.m. The script uses unsupported API that, if at, all only works in the Web UI. I assume it fails, because one of the lines before the true fails and there is no try/catch around.
https://jazz.net/library/article/1093 the last labs explain the API available. It is also possible to debug the Web UI or read the logs.
|
Hi Ralph,
Please find below the complete validation script and logs-
dojo.provide("com.example.MyScript");
dojo.require("com.ibm.team.workitem.api.common.Severity");
dojo.require("com.ibm.team.workitem.api.common.Status");
dojo.require("com.ibm.team.repository.web.client.session.Session");
(function() {
var doDebug = true;
var scriptname = "MyScript";
var Severity= com.ibm.team.workitem.api.common.Severity;
var Status= com.ibm.team.workitem.api.common.Status;
dojo.declare("com.example.MyScript", null, {
validate: function(attribute, workItem, configuration) {
debug("Start:");
var severity = "ERROR";
var message = "Custom error message";
try{
var getAuthenticatedContributor = com.ibm.team.repository.web.client.session.getAuthenticatedContributor;
debug("getAuthenticatedContributor: " + getAuthenticatedContributor);
var loggedInUsername = getAuthenticatedContributor().name;
debug("loggedInUsername: " + loggedInUsername);
debug("severity: " + severity);
debug("message: " + message);
} catch (e) {
debug("Exception: " + e.message);
throw(e);
}
return new Status(Severity[severity], message);
function debug(display){
if(doDebug){
console.log(scriptname + " " + display);
}
}
}
});
})();
_____________
MyScript Start:
MyScript getAuthenticatedContributor: function(){
_4();
return com.ibm.team.repository.web.client.internal.AUTHENTICATED_CONTRIBUTOR;
}
MyScript loggedInUsername: Anmol Rattan
MyScript severity: ERROR
MyScript message: Custom error message
______________
I can see the Red Symbol on the attribute but the save is not getting blocked.
I have applied Attribute Validation as well.
The behavior is same for Conditional script as well.
|
Ralph Schoon (63.5k●3●36●46)
| answered Dec 14 '21, 12:50 p.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER edited Dec 14 '21, 12:51 p.m. Create a simple sample first. Read the documentation and the workshop carefully. For validation as well as conditions it is required to configure an advisor/pre-condition to prevent saving if an error or failed condition is detected.
com.ibm.team.repository.web.client.internal.AUTHENTICATED_CONTRIBUTOR; Is not public API.
|
Your answer
Dashboards and work items are no longer publicly available, so some links may be invalid. We now provide similar information through other means. Learn more here.