Jazz Forum Welcome to the Jazz Community Forum Connect and collaborate with IBM Engineering experts and users

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'.
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;
        }
    });
})();

0 votes



3 answers

Permanent link

 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. 

0 votes


Permanent link

 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.

0 votes


Permanent link

 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.

0 votes

Your answer

Register or log in to post 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.

Search context
Follow this question

By Email: 

Once you sign in you will be able to subscribe for any updates here.

By RSS:

Answers
Answers and Comments
Question details
× 6,121

Question asked: Dec 10 '21, 10:31 a.m.

Question was seen: 1,299 times

Last updated: Dec 15 '21, 4:58 a.m.

Confirmation Cancel Confirm