Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.

While loop with Or statement

Avatar

Former Community Member
Is it possible to have a while loop with the or (||) comparison.



I've been trying while (x != 1 || 2) and variations such as while (x != 1 || x != 2).



When I have just one statement the loop performs as normally, but when I add the second argument it seems to become an infinite loop, I've tested to make sure the variable is updating so I'm pretty sure the problem lies in my loop statement.



I am fairly new to javascript so this might be a case of me trying to use features from other languages that arent available in javascript.



Thank you



Paul
14 Replies

Avatar

Level 4
I'm pretty sure any valid boolean expression can be used in a while loop, and I don't see anything wrong using with your second version (x != 1 || x != 2). However I don't think that with that statement any value of x will allow the OR statement to evaluate to false, so the loop will continue forever:



x=0 = ( true || true ) = result true

x=1 = ( false || true ) = result true

x=2 = ( true || false ) = result true

x=3 = ( true || true ) = result true



Perhaps you mean to use the AND operator && which would mean the loop would break if x was either 1 or 2.

Avatar

Former Community Member
whenever ive tried to use the && operator it generates the following error:



XML parsing error: not well-formed (invalid token) (error code 4), line 59, column 23 of file.



This is a sample of the loop ive been trying to use:



var Temp = 1;



while (Temp != 2 && Temp != 3)

{

Temp = app.response({

cQuestion: "Enter Temp",

cTitle: "Testing:",

cDefault: "",

});

TextField1.rawValue = Temp;

}

Avatar

Level 4
All that syntax appears to be fine (I'm assuming app.response is a method you have defined elsewhere), which part exactly in that code equates to line 59, column 23?



I put this on a click event of a button (only slightly modified to define a replacement for app.response):



>var Temp = 1;



>while (Temp != 2 && Temp != 3)



>{



>Temp = response({



>cQuestion: "Enter Temp",



>cTitle: "Testing:",



>cDefault: "",



>});



>TextField1.rawValue = Temp;



>}



>function response(obj) {



> xfa.host.messageBox("o:"+obj.cTitle);



> return 2;



>}



Works ok for me. Are you using Designer ES, and have you tried the validate syntax function (book with a green tick above script window) and looked for errors?

Avatar

Level 4
OK, just checked on app.response and it's an Acrobat scripting method I wasn't familiar with. I assume that the code you have is for calling it in Acrobat scripting, as you wouldn't call it with an object which has certain properties like that in Designer.



Should be:



>var Temp = 1;



>while (Temp != 2 && Temp != 3)



>{



>Temp = app.response("Enter Temp","Testing:","");



>TextField1.rawValue = Temp;



>}

Avatar

Former Community Member
Thanks for the help, the code is called from a button click event.



I tried out both sets of code you posted and both generate the same error I have been receiving. The line mentioned in the error is the while statement. There seems to be something about the && operator that my copy of LiveCycle doesnt like.



I know that in C++ and VB you sometimes have to include libraries in your code to allow certain functions, does javascript have anything like that? It just seems odd that || is allowed but && so far has not been.



Again thanks for the help

Avatar

Level 4
No, the only thing is that the script must be set to Javascript and not Formcalc from the drop down at the top corner of the script editor, but I would think you've already done this or the || wouldn't work either.



If you navigate to the exact Line/Column indicated by the error message, is it actually the & character there, or something else?

Avatar

Former Community Member
hi,

Can u please help me in guiding how to remove the displaying text "warning:javascript window" in the app.response window...

Thanks a lot

BalajiGurumurthy

Avatar

Former Community Member
You cannot remove that text ...it is there so that users know that javascript is running.

Avatar

Former Community Member
Actually my query is when i try to make a dialog box open through

"app.response" or through "commit:function (dialog)" function it works fine but the thing is 'warning:javascript window' text is visible but i need to hide this or please suggest an alternative idea for opening a dialog box which is being used as a SEARCH functionality

Thanks a lot

BalajiGurumurthy

Avatar

Former Community Member
The following code is an example of webservices calling..

var response = SOAP.request({

cURL: myURL,

oRequest: req,

cAction: mySOAPAction,

bEncoded: false,

cNamespace: myNamespace,

cResponseStyle: SOAPMessageStyle.Message

});

app.alert(response[0].soapValue[1].soapValue);

The thing is that can u suggest me an idea how to parse the variable 'response' and get the values.

Avatar

Former Community Member
Why not put the response into a hidden field then you can parse it all you want. There is no way to remove the 'warning:javascript window' from the response. That woudl be a breach of security.

Avatar

Former Community Member
var myURL = "?wsdl url";<br />var myNamespace ="http://adobe.com/workflow/services/<webservice name>";<br />var mySOAPAction = "?wsdl url";<br />app.alert(myURL);<br />var aStr = {soapType: "xsd:string", soapValue: "GetUserList:vij"};<br />var req = {};<br />req["synchronousInvoke"] = {a: aStr};<br />var response = SOAP.request({<br />cURL: myURL,<br />oRequest: req,<br />cAction: mySOAPAction,<br />bEncoded: false,<br />cNamespace: myNamespace,<br />cResponseStyle: SOAPMessageStyle.Message<br />});<br /><br />app.alert(response);<br /><br />I have a doubt regarding this variable "response". Actually when i just try to print what the variable contains it is returning as '[object Aggregate]' - but what is it actually denoting and am not getting any idea of really what it is. Only if i know of what that variable is returning then i can able to proceed.<br />Please can u jus simply explain a sample code for clear understanding.<br />Thanks a lot<br />BalajiGurumurthy

Avatar

Former Community Member
You are getting the entire Soap response not a string so you should be able to interogate the response object by pathing your way down to the node that you want in the response. If you are usinng Acrobat there is a Soap monitor that will allow you to see the response object. You will have to turn on the Javascript debugger to use it (only in Acrobat).