Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

Trying to have a script work on all pages

Avatar

Level 1

 

Hello,

I am having a problem with my script in livecycle. I am trying to create random generated numbers, but the code i have only works on one page. I have 128 pages i need it to cover. The code is as follows. Please let me know if you have a solution. Oh and the boxes i have created are named the same throughout all of the pages. I tried setting everything to global, but that just produces the same numbers on each page. I would like to avoid having to write script for each page.

Thanks

topmostSubform.Page1.ButtonCreateCards::click - (JavaScript, client)

var varN1 = Math.round(1 + (15-1)*Math.random());

var varN2 = Math.round(1 + (15-1)*Math.random());

while (varN2 == varN1)

{

varN2 = Math.round(1 + (15-1)*Math.random());

}

var varN3 = Math.round(1 + (15-1)*Math.random());

while (varN3 == varN1 || varN3 == varN2)

{

varN3 = Math.round(1 + (15-1)*Math.random());

}

var varN4 = Math.round(1 + (15-1)*Math.random());

while (varN4 == varN1 || varN4 == varN2 || varN4 == varN3)

{

varN4 = Math.round(1 + (15-1)*Math.random());

}

var varN5 = Math.round(1 + (15-1)*Math.random());

while (varN5 == varN1 || varN5 == varN2 || varN5 == varN3 || varN5 == varN4)

{

varN5 = Math.round(1 + (15-1)*Math.random());

 

}

B1.rawValue = varN1;

B2.rawValue = varN2;

B3.rawValue = varN3;

B4.rawValue = varN4;

B5.rawValue = varN5;

var varN1 = Math.round(16 + (30-16)*Math.random());

var varN2 = Math.round(16 + (30-16)*Math.random());

while (varN2 == varN1)

{

varN2 = Math.round(16 + (30-16)*Math.random());

}

var varN3 = Math.round(16 + (30-16)*Math.random());

while (varN3 == varN1 || varN3 == varN2)

{

varN3 = Math.round(16 + (30-16)*Math.random());

}

var varN4 = Math.round(16 + (30-16)*Math.random());

while (varN4 == varN1 || varN4 == varN2 || varN4 == varN3)

{

varN4 = Math.round(16 + (30-16)*Math.random());

}

var varN5 = Math.round(16 + (30-16)*Math.random());

while (varN5 == varN1 || varN5 == varN2 || varN5 == varN3 || varN5 == varN4)

{

varN5 = Math.round(16 + (30-16)*Math.random());

}

I1.rawValue = varN1;

I2.rawValue = varN2;

I3.rawValue = varN3;

I4.rawValue = varN4;

I5.rawValue = varN5;

5 Replies

Avatar

Level 7

Try setting it up as a script object--turn it into a function.

Avatar

Level 1

can you elaborate a bit on turning it into a function. I am confused on turning it all into a complete function. I appologize, i am still brand new to the software. I can write java, but still not 100% on using the software.

Thanks

Avatar

Level 7

I may not understand your problem completely. If you want all pages to have access to the same set of 5 random numbers, then use "variables" (that are global in scope--don't confuse this with setting field binding to global). You create "variables" (lets name them:  var1,var2, var3, var4, var5) in the form File>Form Properties>Variables tab. Then you reference them (say, from the calculation event of a numeric field) like this:

this.rawValue = var1.value;  //rawValue for fields  .value for variables  (important)

////////////////////////////////////////////////////

If you wanted just to be able to produce random numbers (a different set for each page/button) then a script object would be helpful

This link explains in detail:

http://help.adobe.com/en_US/livecycle/9.0/designerHelp/index.htm?content=000818.html#1586693

Briefly, you create a reusable function and store it in a Script Object (a place that all fields have access to). Then you reference that object, say on a button click. Lets say you have a script object named myScriptObject and you define a function on it called randomNumber()

on the button click you can use that function by referencing it like this

myScriptObject.randomNumber();

So, with every click you run the script from any button on your form that has the reference above. Don't set the fields to Global and you'll get different results on the different pages

You can pass defined parameters to the function inside the (), like if you needed to seed the random number generator function, you could pass a parameter like this:

myScriptObject.randomNumber(someParameter);

or multiple parameters

myScriptObject.randomNumber(someParameter, [anotherOne],[YetAnotherOne],[etc.]);

Your function can also set the values of variables, too. Seeing how I don't understand your objective completey, I don't know what parts of the above you'll find useful (if any).

something like:

function randomNumber()     {

     do some stuff;

     var1.value = something;

     var2.value = somethingelse;

     var3.value = etc;

}

then

myScriptObject.randomNumber();  //this reference placed on a button click, would update the variables

and since the variables are global in scope, any script anywhere could access it.

Is any of this helpful?

Stephen

Avatar

Level 1

It looks like that would work, but i don't see where i can create a global object. I can only see where i can make an object per page. I have been copying and pasting my setup and script for the past hour. it is getting old. What i am trying to do, and it sounds dumb, is make custom bingo cards. i have 5 numeric values across and 5 numeric values down. I have programmed it so when you hit the object button, it randomly creates numbers in each spot so that each card is different and random. i have 500 cards to create, and the copy and pasting is killing me. If you can tell me how to create the global object, then i think i can solve the rest.  Every time i have attempted it, it only works on the current page. and you were correct when i thought changing the binding options to global. That didn't work. I think you are the closest to solving my issues.

Thank you very much

Avatar

Level 7

Hi, now I get it.

OK, I hate to tell you this, but you should know--it can be done with 128 instances of 1 page, instead of 128 pages. You could create a cover sheet with input parameters, like a field that you enter how many cards and a button to produce them--now you're up to 2 pages total.

I don't have time to draw it all out for you, but I would encourage you to think of your project in the way I just described.

Stephen