Expand my Community achievements bar.

SOLVED

How do I set global variables for use by ALL form1.#subform[0] items?

Avatar

Level 2

Hi All,

I know how to code javascript but am new to Adobe LiveCycle.  When I open script editor, I have the following code (all code is in un-bolded):

----- form1.#subform[0]::initialize: - (FormCalc, client) ------------------------------------------

//////////////////////////////
// BEGIN: SET GLOBAL PRICES //
//////////////////////////////

var Cityscope_Sydney_CostUser1 = 60.39;
var Cityscope_Sydney_CostUsers2to5 = 3.02;
var Cityscope_Sydney_CostUsers6to20 = 1.21;
var Cityscope_Sydney_CostHardCopyWithOnline = 14.59;
var Cityscope_Sydney_CostHardCopyWithoutOnline = 54.67;
var Cityscope_Sydney_CostHardCopyAdditional = 14.59;

var Cityscope_NorthSydney_CostUser1 = 48.40;
var Cityscope_NorthSydney_CostUsers2to5 = 2.42;
var Cityscope_NorthSydney_CostUsers6to20 = 0.97;
var Cityscope_NorthSydney_CostHardCopyWithOnline = 14.59;
var Cityscope_NorthSydney_CostHardCopyWithoutOnline = 43.54;
var Cityscope_NorthSydney_CostHardCopyAdditional = 14.59;


////////////////////////////
// END: SET GLOBAL PRICES //
////////////////////////////

----- form1.#subform[0]::enter: - (FormCalc, client) -----------------------------------------------

----- form1.#subform[0]::exit: - (FormCalc, client) ------------------------------------------------

----- form1.#subform[0]::calculate: - (FormCalc, client) -------------------------------------------

----- form1.#subform[0]::validate: - (FormCalc, client) --------------------------------------------

----- form1.#subform[0]::preSave - (FormCalc, client) ----------------------------------------------

<<======= etc etc etc =======>>

----- form1.#subform[0].Item1Cost::initialize: - (JavaScript, client) ------------------------------

----- form1.#subform[0].Item1Cost::enter: - (FormCalc, client) -------------------------------------

----- form1.#subform[0].Item1Cost::exit: - (FormCalc, client) --------------------------------------

----- form1.#subform[0].Item1Cost::calculate: - (JavaScript, client) -------------------------------

//Store form values in user-friendly names.
var AreaSelected = Item1Area.rawValue;
var NumberOfUsersSelected = Item1Users.rawValue;

//Declare other vars.
var Users1Calculation;
var Users2to5Calculation;
var Users6to20Calculation;


//Calculate individual User Cost "components" based on number of users selected for the area.
switch(true)
{
case (NumberOfUsersSelected < 2):
  Users1Calculation = NumberOfUsersSelected * Cityscope_Sydney_CostUser1;
  Users2to5Calculation = 0.00;
  Users6to20Calculation = 0.00;
  break;
case (NumberOfUsersSelected > 1 && NumberOfUsersSelected < 6):
  Users1Calculation = Cityscope_Sydney_CostUser1;
  Users2to5Calculation = (NumberOfUsersSelected - 1) * Cityscope_Sydney_CostUsers2to5;
  Users6to20Calculation = 0.00;
  break;
case (NumberOfUsersSelected > 5):
  Users1Calculation = Cityscope_Sydney_CostUser1;
  Users2to5Calculation = 4 * Cityscope_Sydney_CostUsers2to5;
  Users6to20Calculation = (NumberOfUsersSelected - 5) * Cityscope_Sydney_CostUsers6to20;
  break;
default:
  alert("BROKEN: Calculate individual User Cost components based on number of users selected for the area.");
}

//apply total cost for this item
Item1Cost.rawValue = Users1Calculation + Users2to5Calculation + Users6to20Calculation;

----- form1.#subform[0].Item1Cost::validate: - (FormCalc, client) ----------------------------------

----- form1.#subform[0].Item1Cost::mouseEnter: - (FormCalc, client) --------------------------------

----- form1.#subform[0].Item1Cost::mouseExit: - (FormCalc, client) ---------------------------------

----- form1.#subform[0].Item1Cost::change: - (FormCalc, client) ------------------------------------

----- form1.#subform[0].Item1Cost::full: - (FormCalc, client) --------------------------------------

----- form1.#subform[0].Item1Cost::mouseUp: - (FormCalc, client) -----------------------------------

----- form1.#subform[0].Item1Cost::mouseDown: - (FormCalc, client) ---------------------------------

----- form1.#subform[0].Item1Cost::click: - (FormCalc, client) -------------------------------------

----- form1.#subform[0].Item1Cost::preSave - (FormCalc, client) ------------------------------------

----- form1.#subform[0].Item1Cost::postSave - (FormCalc, client) -----------------------------------

----- form1.#subform[0].Item1Cost::prePrint - (FormCalc, client) -----------------------------------

----- form1.#subform[0].Item1Cost::postPrint - (FormCalc, client) ----------------------------------

----- form1.#subform[0].Item1Cost::preSubmit:form - (FormCalc, client) -----------------------------

----- form1.#subform[0].Item1Cost::docReady - (FormCalc, client) -----------------------------------

----- form1.#subform[0].Item1Cost::docClose - (FormCalc, client) -----------------------------------

----- form1.#subform[0].Item1Cost::ready:form - (FormCalc, client) ---------------------------------

----- form1.#subform[0].Item1Cost::ready:layout - (FormCalc, client) -------------------------------

----- form1.#subform[0].Item1Users::initialize: - (FormCalc, client) -------------------------------

----- form1.#subform[0].Item1Users::enter: - (FormCalc, client) ------------------------------------

----- form1.#subform[0].Item1Users::exit: - (FormCalc, client) -------------------------------------

----- form1.#subform[0].Item1Users::calculate: - (FormCalc, client) --------------------------------

----- form1.#subform[0].Item1Users::validate: - (FormCalc, client) ---------------------------------

----- form1.#subform[0].Item1Users::mouseEnter: - (FormCalc, client) -------------------------------

----- form1.#subform[0].Item1Users::mouseExit: - (FormCalc, client) --------------------------------

----- form1.#subform[0].Item1Users::change: - (FormCalc, client) -----------------------------------

----- form1.#subform[0].Item1Users::full: - (FormCalc, client) -------------------------------------

----- form1.#subform[0].Item1Users::mouseUp: - (FormCalc, client) ----------------------------------

----- form1.#subform[0].Item1Users::mouseDown: - (FormCalc, client) --------------------------------

----- form1.#subform[0].Item1Users::click: - (FormCalc, client) ------------------------------------

----- form1.#subform[0].Item1Users::preSave - (FormCalc, client) -----------------------------------

----- form1.#subform[0].Item1Users::postSave - (FormCalc, client) ----------------------------------

----- form1.#subform[0].Item1Users::prePrint - (FormCalc, client) ----------------------------------

----- form1.#subform[0].Item1Users::postPrint - (FormCalc, client) ---------------------------------

----- form1.#subform[0].Item1Users::preSubmit:form - (FormCalc, client) ----------------------------

----- form1.#subform[0].Item1Users::docReady - (FormCalc, client) ----------------------------------

----- form1.#subform[0].Item1Users::docClose - (FormCalc, client) ----------------------------------

----- form1.#subform[0].Item1Users::ready:form - (FormCalc, client) --------------------------------

----- form1.#subform[0].Item1Users::ready:layout - (FormCalc, client) ------------------------------

...and so on and so forth....

In short, I want the code within:

----- form1.#subform[0].Item1Cost::calculate: - (JavaScript, client) -------------------------------

...to be able to access the variables I have created in:

----- form1.#subform[0]::initialize: - (FormCalc, client) ------------------------------------------


(I have assumed that this is where I would store Global variables)

At this stage, the global variables cannot be accessed with the configuration above.  The only was I can get this to work is to cut and paste the global vairables into each form1.#subform[0] item, which of course defeats the purpose of global variables!  I plan to have many more items so would not want to duplicate the global variables for all of them!

Can somebody show me how to do this?

Any help is very much appreciated!

Thanks

Stanbridge

Message was edited by: stanbridgej - colors and or fonts won't save.  Have bolded my question to make code (non-bolded) easier to read (I hope).

1 Accepted Solution

Avatar

Correct answer by
Former Community Member

I haven't used Formccalc, but I thought it would be the same regardless. Insert a scripting object near the top of the hierarchy and call it, e.g. "sco". Paste the global variables. Then reference the variables from wherever as sco.Cityscope_Sydney_CostUser1 etc. Do an

app.alert(sco.Cityscope_Sydney_CostUser1);

from one of the fields. If the debugger is turned on, it will tell you if it can't resolve the reference as "sco. In which case, you might have to use the som expression to reference the scripting object, e.g.

var scoScript = xfa.resolveNode("topOfHierarchy.sco");

scoScript.Cityscope_Sydney_CostUser1

but if as close as possible to the top of hierarchy the above should work.

View solution in original post

9 Replies

Avatar

Level 2

Global Variables are configured via

File -> Form Properties ... -> Variables (tab)

Avatar

Level 2

Hi MorisTM,

Thanks for the reply!

Yes, I saw that option (I should have mentioned I already knew about it), but was wondering if there is a way I can do this via code.

There are two reason I want to be able to do it via code (only one of which may be valid):

1) I can automatically generate my pricing code form another inhouse app.

2) I am hoping that later on once I get this working I will be able take it a step further and get the data directly from a MySQL database!

Cheers though!

Any other suggestions?

Regards,

Stanbridge

Avatar

Level 2

If you are heading in that direction, for now put your global variables into a xml data file, and create a Data Connection based on the Sample XML Data.

Later you can change this to a Database Data Connection.

Avatar

Level 2

That sounds more like what I'm after!

Now...  how do I do that?! 

Do you know of any documnetation/URLs I should go and read?  (I couldn't find any prior to my initial post here)

Otherwise, is this something you can explain/demonstrate easily enough?

Cheers,

Stanbridge

Avatar

Level 2

There are samples in Adobe LiveCycle Designer itself, under Help menu.

Avatar

Correct answer by
Former Community Member

I haven't used Formccalc, but I thought it would be the same regardless. Insert a scripting object near the top of the hierarchy and call it, e.g. "sco". Paste the global variables. Then reference the variables from wherever as sco.Cityscope_Sydney_CostUser1 etc. Do an

app.alert(sco.Cityscope_Sydney_CostUser1);

from one of the fields. If the debugger is turned on, it will tell you if it can't resolve the reference as "sco. In which case, you might have to use the som expression to reference the scripting object, e.g.

var scoScript = xfa.resolveNode("topOfHierarchy.sco");

scoScript.Cityscope_Sydney_CostUser1

but if as close as possible to the top of hierarchy the above should work.

Avatar

Level 2

Thanks fbook,

Dammit, I didn't even notice I still had it set to FormCalc in the initialise.  That said, I changed this to JS and still no luck referencing the vars within in another section.

I think I understand your comments re referencing, but how do I "Insert a scripting object near the top of the hierarchy"?  (sorry, probably a noob question).

Is that just adding another (do these represent "scripting objects"?):

----- form1.#subform[0]::initialize: - (JavaScript, client) ----------------------------------------

Cheers mate,

Stanbridge

Avatar

Former Community Member

HI,

No, that's just an event. Right click on the hierarchy, at the top level if possible. You will see an option called, "Instert Script Object". This is where you put your common functions, and I usually put my variables there too. Once it is inserted, click on it and rename it to something like, "sco". Pressing F2 will also let you rename it.

Then do as mentioned before.

Avatar

Level 2

That's Brilliant fbook!

Works a treat.  Thanks heaps!

Cheers,

Stanbridge

The following has evaluated to null or missing: ==> liqladmin("SELECT id, value FROM metrics WHERE id = 'net_accepted_solutions' and user.id = '${acceptedAnswer.author.id}'").data.items [in template "analytics-container" at line 83, column 41] ---- Tip: It's the step after the last dot that caused this error, not those before it. ---- Tip: If the failing expression is known to be legally refer to something that's sometimes null or missing, either specify a default value like myOptionalVar!myDefault, or use <#if myOptionalVar??>when-present<#else>when-missing. (These only cover the last step of the expression; to cover the whole expression, use parenthesis: (myOptionalVar.foo)!myDefault, (myOptionalVar.foo)?? ---- ---- FTL stack trace ("~" means nesting-related): - Failed at: #assign answerAuthorNetSolutions = li... [in template "analytics-container" at line 83, column 5] ----