Expand my Community achievements bar.

Guidelines for the Responsible Use of Generative AI in the Experience Cloud Community.

JAVASCRIPT PROBLEM in designer!

Avatar

Former Community Member
hello.

i used javascript for professional for some time and wouldnt say i had any serious problems... eventually i worked things out.. but the same scripts on designer do not work.. all i can do is app.alert() .. thats the only thing that works - if i add an if statement (on mouse up) such as



if radiobutton.value == "1"

{

app.alert()

}



it doesnt do anything.. could someone please help?

what is so different that nothing works!?



thanks a lot...
10 Replies

Avatar

Level 7
There is almost no case in which the same scripts will work. In

particular, the way of getting the values of fields is not the same in

Designer. A few objects and methods (e.g. the app object) are shared

between both worlds.



You should check, at this point, whether your reasons for going to

Designer are strong enough to relearn everything. If they are, check

out the Designer help document, which should get you started with

Designer JavaScript.



Aandi Inston

Avatar

Former Community Member
CdThomas,



You should be able to search for many examples that work in this forum. Anyway, you can find an example here

http://66.34.186.88/LiveCycleSamples/.3bbb1872.pdf



Basically, you almost have the syntax correct. This is what I used in the example on the "mouseUp" event.



if (RadioButtonList.radio1.rawValue == 1)

{

app.alert("You have chosen 'seclection 1'.");

}



Just to make sure you have the "language" set as "javascript" in the script editor.

Avatar

Former Community Member
Unfortunately, despite the fact that designer does support standard javascript, whether or not it is programmed to handle all javascript events/functions remains to be seen. You can be pretty confident though that most generic processes will still work. Things such as looping structures, if/then/else's, and switch statements are pretty consistent.



for example:



for(i=1;i<11;i++){

app.alert(i);

}

Will alert 10 times starting with 1 going to 10;



switch(myVal){

case '1':

//do something

break;

case '2':

//do something

break;

}



This simple switch statement works as it would in regular javascript.

Avatar

Former Community Member
I need help badly.

I need to load the data from an xml file into a text field in designer

using javascript and then go through each node in the loaded xml and compare that with form fields in designer and if matching fill the value(node's value from the loaded xml) in form fields.



Please give ur suggestions.



Thanks in advance!!!



regards,

sowmya

Avatar

Former Community Member
Hi David,

I did go through your suggestions in the above said thread.



But I need this to work on the loading of the pdf and not on a button click.



This is the code I tried on form:ready event:



if(app.viewerVersion >=7)

{

event.target.importDataObject("xmldata","/E/testxml.xml");

var oData = event.target.getDataObjectContents("xmldata");

var sData = util.stringFromStream(oData);

var oXML = testxml.parse(sData, true);

event.target.removeDataObject("xmldata");



app.alert(oXML.Name.value);

}



It gave me the following error:



TypeError: Invalid argument type.

Global.getDataObjectContents:12:initialize undefined:Exec

===> Parameter cName.

NotAllowedError: Security settings prevent access to this property or method.

Global.importDataObject:3:Doc undefined:Open



Any suggestions would be very welcome as I am hard pressed for time.



Thanks a lot for your help.



regards,

Sowmya

Avatar

Former Community Member
As the previous message stated, you cannot do this on anything other than a click event due to Security restrictions. Doing this automatically using form:ready will not work as you are trying to bypass the restriction on automatically loading data (and potentially modifying the document) without the users knowledge.



Your only options if you try and do it without the users knowledge, is to 1) Use LifeCycle Forms, 2) Use a webservice call or 3) use the XDP package format

Avatar

Former Community Member
Hi David,

Even when I put in a button and put all my code in click event, I stil get the following error when I click the button:



NotAllowedError: Security settings prevent access to this property or method.

Global.importDataObject:4:click undefined:Exec



Please give ur valuable suggestions.



Thanks and regards,

Sowmya

Avatar

Level 7
Putting it on a button doesn't change things.



Aandi Inston

Avatar

Former Community Member
Do you have Acrobat 7 install (not Reader)? I currently use 7.0.2 and have saved my form as a Dynamic form.



Also, if you use the second parameter on the importDataObject then there is a further restriction - "If the cDIPath parameter is specified, then this method can only be executed during batch, console or menu events, or through an external call (for example, OLE). See also Privileged versus Non-privileged Context. The Event Object contains a discussion of Acrobat JavaScript events."



The original example did not use the second parameter.