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

Does validation scripts allow the use of XMLHttpRequest?

Hi everyone,

My client is developing a "validator" type script and came across the following question:

When a "XMLHttpRequest" object is inserted  into the script, the script stops validating on the workitem save event. The validation works on the form, it just does not work at the time of the save event.

The problem happens from the time the line "var xmlhttp = new XMLHttpRequest ();" runs.

Our question for the experts here is: does validation scripts allow the use of XMLHttpRequest?

If necessary I can upload part of the code in which the object is called.

0 votes



One answer

Permanent link
You have to be very careful with this one - client side validation can use pretty much anything your browser's Javascript engine will understand *AT YOUR OWN RISK*, but the server-side Javascript engine is a lot more limited.

Not only does it not have the full set of functionality, it may also be behind firewalls, and it's also quite an old version of ECMAScript (I have just found out it doesn't support <string>.includes() or <array>.includes()).

I have found I have the most success when I use the extended dojo object jazz.client, but it really depends on what you're doing. The best thing about the jazz.client version of xhr is that it understands the Jazz authentication process.

This is what I do:

dojo.require("jazz.client");
..

(function() {
  var jazzClient = jazz.client;
..

  var someFunction = function(team, role) {
     var xhrArgs = {
        url : '<my url>',
        headers : {
          'Accept' : 'application/xml'
        },
        handleAs : 'xml'
     };

    return jazzClient.xhrGet(xhrArgs).then(function(data) {
          console.log(data);        
          return data;
       });
   };

EDIT: By the way you can use this check to see if the script is executing on the client or the server:
if (typeof dojo.xhrGet === 'undefined') {
  console.log('I am on the server'); //this will print in ccm.log
} else {
  console.log('I am on the server'); //this will print in the browser Dev console
}

0 votes

Comments

 when I put in a calculation java script it say that there is a problem loading the script


Then you have an error in your script

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
× 10,930
× 7,491
× 10

Question asked: Jun 18 '19, 3:26 p.m.

Question was seen: 2,629 times

Last updated: Jul 16 '19, 7:35 p.m.

Confirmation Cancel Confirm