cancel
Showing results for 
Search instead for 
Did you mean: 

Javascript for reading the result of xfa.resolveNodes by index

Former Member

Hi,

I've created an Adobe Interactive form, which allows a user to enter a material number, with the material number being validated against a list of materials embedded into the form, and the Old Material Number and Description being automatically populated if a match is found.  The form is created with around 3,000 materials embedded, which gives an acceptable file size of around 600Kb.  This is a proof-of-concept form at the moment to see if it's worth using this technique.

The following Javascript is contained within the Exit Event of the Material field:

(IT_MAT is the internal table of materials, mapped to the context)

// Read all Material data

  var Mats = xfa.resolveNodes("$record.IT_MAT.DATA[*]");
  var numRows = xfa.resolveNodes("$record.IT_MAT.DATA[*]").length;

// Loop through until a match is found
  var found = false;
  for (var i = 0; i < numRows; i++) {

    if (this.rawValue == Mats.item(i).MATNR.value) {

      BISMT.rawValue = Mats.item(i).BISMT.value;
      MAKTX.rawValue = Mats.item(i).MAKTX.value;

      found = TRUE;
      break;    
    }
  }

// Invalid Material
  if (!found) xfa.host.messageBox("Invalid Material " + this.rawValue);

This works perfectly, but the only problem is the inefficiency of having to loop through 3,000 records to find out that the entered material is invalid, which takes a few seconds.

My question is how to search the "Mats" object by key, in the same way as you would in ABAP with a READ TABLE itab WITH KEY matnr = matnr.  I thought that the indexOf method would work with the Mats object, but it doesn't.

There is some XFA documentation at the following location, but it doesn't help either.

http://www.adobe.com/content/dam/Adobe/en/devnet/acrobat/pdfs/acro7jsguide.pdf

Thanks,

Pete

Accepted Solutions (0)

Answers (1)

Answers (1)

Florian
Active Contributor
0 Kudos

Hi Peter,

did you try to solve your problem with find / indexof?

You know, something like

Mats.find(BISMT.rawValue)

or

Mats.indexOf(BISMT.rawValue)


~Florian

Former Member
0 Kudos

Hi Flroian,

Yes I did try using indexOf, but it didn't work, and the "find" method isn't available to Mats.

Thanks,

Pete