Jump to content

Two instances of a Random Number


Recommended Posts

I'm working on a project which requires the use of a random number (between 0 and 9) to be placed at the end of a barcode string. That same number also needs to be included in the human readable text below the barcode.


All my attempts have resulted in different random numbers being generated in each location. Is there an easy way to generate a random number then use in multiple locations?


My guess is it will involve an OnRecordStart rule--but I can't seem to get it to come out correctly.


Thanks in advance for any suggestions!



Link to comment
Share on other sites

You're right, you want to generate that random number at the start of every record (in the OnRecordStart call back rule) and then apply it to your barcode string as well as the human readable string.


It's hard to say for sure without seeing how you currently have your template set up but I think you could do something like this:

var barcode = "Barcode"; // The name of your barcode field
var ran = Math.random();
ran = Math.floor(ran*10);

FusionPro.Composition.AddVariable(barcode,Field(barcode) + ran);


This adds the randomly generated number to the value of your field "Barcode" so any text frame that returns Field("Barcode") will return the value + the random digit at the end.


Again, I'm just taking a stab in the dark at how you're template is set up. If this doesn't work, you may want to upload a sample of your template and data for a more tailored solution.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...