Expand my Community achievements bar.

Setting and accesing Global Variables

Avatar

Level 1

Hello everybody,

 

i am pretty new to the LifeCycleDesigner and especially JavaScript. So, bear with me and my and my basic questions, which I am still unable to really understand (even after googling for days).

I am using the designer within SAP and want to create a form for purchase orders. In this form I want to have a global variable, which I can fill from every page and also access the stored data.

As of now I created a Variable in the Form Properties and tried to fill and access it, but without any success.

I know that I have to use “XFA.records<Fieldname>.value” to interact with the variable but with no results so far.

Sorry for the probably easy question, but I am really struggling with this task.

Maybe somebody can post some scrrenshots or sample code.

 

Thanks a lot!

 

3 Replies

Avatar

Level 10

Hi,

 

the variables you're define under the form properties are read only, since they are hardcoded into the template which can't be modified by a PDF viewer. However, if you only need static data, you can still use them. Given you variable is named "formVar" and contains an array ["Value 1", "Value 2", "Value 3"], you can simply access it via JavaScript. 

 

var cArray = formVar.value; // returns the content of formVar as string

 

var aArray = eval(formVar.value); // returns the content of formVar as string and converts it into an a array

 

Avatar

Level 1

Hello,

Thanks for the Help but unfortunately i still am unable to solve my Problem.

This is my cuurent Code:

 

1. Field Saldo which is printed per page (here i also use an Overflow):

data.BODY.scr_Item_Fuss.Uebertrag.scr_UebNETWR::calculate - (JavaScript, both)
var lo_fields = xfa.layout.pageContent(xfa.layout.page(this)-1, "field", 0);
var lv_wert_netwr = 0;
//Addition der Werte vom Feld "NETWR" der aktuellen Seite
for (var s=0; s <= lo_fields.length-2; s++) //Schleife über alle Felder der Seite { if (lo_fields.item(s).name == "NETWR") //Abfrage auf Feld für den Nettowert { lv_wert_netwr = lv_wert_netwr + lo_fields.item(s).rawValue; //Summe Werte Feld }

2. Scriptobject:

data.#variables[0].Main - (JavaScript, client)
function FunktionNETWRAdd(Parameter1) 
{
  if ( typeof counter_netwr == 'undefined' )
   {
      counter_netwr = 0;
   }
   
  //Erhöhe den Gesamtwert um den Wert der jeweiligen Ausgabeseite
   counter_netwr = counter_netwr + Parameter1;
   
return counter_netwr;   //Rückgabeparameter mit Gesamtwert inklusive jeweils letzter Ausgabeseite
}

 

3. Field Saldo which should only be printed on the last page:

data.BODY.scr_Item_Fuss.Uebertrag.Saldo::calculate - (JavaScript, both)
this.rawValue = lv_wert_netwr.value;

 

Unfortunately i cannot return any Value on the Field 3. of the last Page. Nonetheless the Values are printed on Field 1. per page.

 

Thanks in advance!

Avatar

Level 10

Sorry, you lost me. What has you comment to do with the initial question?