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

how to know it is in web context or not by using javascript for client?

 

Hi Someone who may concern,
 
    We are on 6.04 RTC,
    We noticed the server log reported the following error when we deploy the java script code to access current user.
org.mozilla.javascript.EcmaError: TypeError: Cannot read property "web" from undefined 

   The code is like this: 
dojo.provide("com.gm.getCurrentUserValueProvider");
dojo.require("com.ibm.team.workitem.api.common.WorkItemAttributes"); 
dojo.require("com.ibm.team.repository.web.client.session.Session"); 

(function() {
    var getAuthenticatedContributor = com.ibm.team.repository.web.client.session.getAuthenticatedContributor;   
    var WorkItemAttributes = com.ibm.team.workitem.api.common.WorkItemAttributes;

   dojo.declare("com.gm.getCurrentUserValueProvider", null, {

        getValue: function(attribute, workItem, configuration) {
var loggedinUser = getAuthenticatedContributor().itemId;
console.log(loggedinUser);
      }

  We noticed it can only work on web context, so, what should we do if we want to add a condition in the code, say, if it is web context, then it can run, otherwise bypass it?

    Thanks!

Best Regards,
Jane Zhou

0 votes



2 answers

Permanent link

As far as I can tell, there is no way to detect the current user if the attribute customization does not run in the web context. This has come up here in the forum many many times and I have never seen anyone being able to come up with a solution that works in the Web as well as in the Clients.

0 votes


Permanent link
I have found the following can be used to see if you are on the server when running a validator or value provider script.

if (typeof dojo.xhrGet === 'undefined' ) {  // is it on the server
             return workItem.getValue(attribute);
}

-- use with caution. For example, a validator may show an X on an item but if the script is to ignore the validation on the server then the save would be allowed even though the item is shown as validated.

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
× 12,043

Question asked: Jul 24 '18, 11:01 p.m.

Question was seen: 2,260 times

Last updated: Jul 31 '19, 5:45 p.m.

Confirmation Cancel Confirm