It's all about the answers!

Ask a question

Conditional script is not blocking save when logged-in user is retrieved


Anmol Rattan (342) | asked Dec 10 '21, 10:31 a.m.
edited Dec 10 '21, 10:32 a.m.

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'.
But as soon as I remove the 2 lines (used to retrieve logged-in user) above the return statement, I can see the error  'State is not modifiable' and save operation is blocked successfully. 

So, basically, the save operation is not getting blocked when the logged-in user is retrieved. 
I also observed the same behavior in Validation script.

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



permanent link
Ralph Schoon (61.8k33643) | 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. 


permanent link
Anmol Rattan (342) | answered Dec 14 '21, 9:23 a.m.

 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.


permanent link
Ralph Schoon (61.8k33643) | 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


Register or to post your answer.