Expand my Community achievements bar.

Help with Sample 'Purchase Order' form

Avatar

Former Community Member

HI Guys,

Have been playing around with the supplied sample file 'Purchase Order'

At the bottom of the form is a Part No., Description and Cost field that populate from a PartNoScript routine.

Have been trying to copy this routine into my own form as its nearly the same.

Question is  - There is a line 2/3rds down

  -  function getDesc(partNumber, descField, itemPrice)

Where is the partName, DescField, ItemPrice store or located. I've looked in all the scripts, looked at the form fields and cannot find what these three relate too.

I'm assume it must be the field name somehow but just cant seem to find them.

Any help much appreciated.

Dave

( With each passing day my knowlage grows stronger - One day I'll take over the world. !! )

var partNo = new Array(" ",

                                                     "580463116",

    "25906311C",

                                                     "25129637J",

                                                     "771128",

                                                     "11198262A",

                                                     "57251",

                                                     "25906312A",

                                                     "51615223D",

                                                     "51615224D",

                                                     "516154CAC");

  // Array of part descriptions.

var partDesc = new Array(null,

                                                            "Electric Fuel Pump",

                                                            "Air Flow Meter",

                                                            "Air Intake Sleeve",

                                                            "Fuel Filter",

                                                            "Fuel Injector Seal Set",

                                                            "Oxygen Sensor",

                                                            "Wiring Harness Upgrade",

                                                            "Brake Caliper left",

                                                            "Brake Caliper right",

                                                            "Brake Master Cylinder right");

// Array of part prices.

var partPrice = new Array(null,

                                                              149.95,

                                                              145.95,

                                                              98.95,

                                                              10.95,

                                                              5.95,

                                                              69.95,

                                                              109.95,

                                                              59.95,

                                                              59.95,

                                                              49.95);

// Populate the part number Drop-down List.

 

function populatePartNo(dropdownField)

{

      var i;

      for (i=0; i < partNo.length; i++)

         dropdownField.addItem(partNo[i]);

}

// Populate the description and unit price fields.

function getDesc(partNumber, descField, itemPrice)   -------------Where are these items/fields, defined or located. ?

{

   var i;

   for (i = 0; i < partNo.length; i++)                    // Go through the entire list of part numbers to find the one that is currently selected.

   {

      if (partNo[i] == partNumber)                              // When we find the part number currently selected.

            {

        descField.rawValue = partDesc[i];          // Put the description in the description field

              itemPrice.rawValue = partPrice[i];          // and put the unit price in the unit price field.

              break;                                                                                // No need to go further if there is a match.

            }

   }

}

11 Replies

Avatar

Level 10

Hi Dave,

The getDesc() function takes three parameters: partNumber, descField and itemPrice. These are assigned values from the script that calls the function. I don't have that version of the form, but I suspect that the function is called from either the exit or click event of the Parts dropdown.

I suspect that the partNumber is assigned the .rawValue of the Parts dropdown, whereas descField and itemPrice are objects in the same row.

Hope that helps,

Niall 

Avatar

Level 10

Okay,

I have located the sample form.

The dropdown list items are populated on the initialise event. This is important as new rows can be added and the event will fire each time a new row is added to the table. This is calling the populatePartNo() function in the partNoScript script object (see variables).

// Populate the part number Drop-down List.

partNoScript.populatePartNo(this);

The other function is called in the change event of the dropdown:

// Populate the description and the unit price when we change the part number.

partNoScript.getDesc(xfa.event.newText, txtDescription, numUnitPrice);

As I suspected it is passing the value of the dropdown and the names of the two objects in the same row.

Does that make sense?

Niall

Avatar

Former Community Member

Thanks Niall

I'm getting close, I 've found the script parts your mentions above and they seem to make sense,

But in Livecycle ( which I'm still getting to grips with ) I simply cant find the 'partNumber' or descField or itemPrice parameters.

  if (partNo[i] == partNumber)  // When we find the part number currently selected.


Ok , so this line is checking to see if  'partNo'. is the same as 'partNumber'  there for i would expect the script to be looking at the valve in the 'txtPartNum'  field on the form.

If I look at the form I dont seem to be able to find any descrption for 'partName'

The reason I ask, is because I can translate the scripts into my own forms but they don't work due the ' if (partNo[i] == partNumber)'  not working because in my form I have not associated any filed with 'partNumber.'

Did that sort of make sense or am I missing the point completely.

In Livecycle is there a way of looking what the drop down box Does/properties ??  for example in Acrobat pro, you can define what happens when enter or exit and drop down box.

Thanks again

Dave


Avatar

Level 10

Hi Dave,

Just to recap:

There is script in the change event of the dropdown that calls the getDesc() function:

// Populate the description and the unit price when we change the part number.

partNoScript.getDesc(xfa.event.newText, txtDescription, numUnitPrice);

This passes three parameters into the function:

  1. xfa.event.newText is the new item in the list that the user has just selected.
  2. txtDescription is the name of the Description object in the same Row that the user has selected from the dropdown.
  3. numUnitPrice is the name of the Unit Price object in the same Row that the user has selected from the dropdown.

So the function is going to be receiving three pieces of information: the new value of the dropdown; the object deference for Description; and the object reference for Unit Price.

Now if we look at the first line of the function:

function getDesc(partNumber, descField, itemPrice)

{

     ...

}

You can see that the function assigns the incoming parameters to new variables: partNumber; descField; and itemPrice. These variables only live within the function.

For the purpose of the script in the function:

  1. partNumber = the value of the txtPartNum dropdown.
  2. descField = the object reference for the txtDesciption object in the Row that called the function.
  3. itemPrice = the object reference for the numUnitPrice object in the Row that called the function.

Passing the value of the dropdown into the function is fairly straightforward (txtPartNum/partNumber). The clever bit is passing the object reference for the other objects in the Row into the function (eg txtDescription/descField).

The script in the function includes a loop, which looks at the array. If the selected part number is in the array, then it sets the value of the txtDescription object in the same Row, by referencing the descField variable:

descField.rawValue = partDesc[i];

Does that make sense?

In relation to the dropdowns:

LC Designer Workspace.png

  • You can access the scripts in the Script Editor (5), including enter event, exit event, etc.
  • You can access most of the dropdown properties in the various palettes (6).

Hope that helps,

Niall

Avatar

Former Community Member

Hi Niall

Did you see that flash of bright light, that was the bulb that suddenly started to shine above my head once I’d read you description.

Wow.. Thanks for making it clear and easy to understand. I was just about the throw the computer out the window and do some thing horrible, like ‘Manual Work’ outside in the yard. You saved the day again.

Had to read the email a few times but YES it makes sense.

Right then, I’m right on to the case and having a play again.

Thank you for your time. Much appreciated.

Dave

Avatar

Level 1

Hello guys,

Is there a limit to the amount of variables that can be put in the array?

I am using the Purchase order from Livecycle and I have not modified anything, the only thing that makes it not to work is the length of the arrays.

the code I am using is ( it works perfectly untill I add more items to the array, I need to add 2794 elemnets. maybe there is another way to achieve what I am trying to do?):

form1.Main.#variables[0].partNoScript - (JavaScript, client)

  // This script object controls the interaction between the part number, description and unit price fields.

  // When you fill the partNo, partDesc and partPrice arrays, make sure they have the same number of array indices in

// each array i.e. for every part number, there should be a matching description and price.

// Array of part numbers.

var partNo = new Array(" ",

                                                     "27001",

"27002",

"27003",

"27004",

// Array of part descriptions.

var partDesc = new Array(null,

                                                            "4M. SHORING BEAM",

"3M. SHORING BEAM",

"2M. SHORING BEAM",

"4,00M. SUPPORT GIRDER");

// Array of part prices.

var partPrice = new Array(null,

                                                              113.44,

87.41,

64.53,

122.91);

// Populate the part number Drop-down List.

 

function populatePartNo(dropdownField)

{

      var i;

      for (i=0; i < partNo.length; i++)

         dropdownField.addItem(partNo[i]);

}

// Populate the description and unit price fields.

function getDesc(partNumber, descField, itemPrice)

{

   var i;

   for (i = 0; i < partNo.length; i++)                    // Go through the entire list of part numbers to find the one that is currently selected.

   {

      if (partNo[i] == partNumber)                              // When we find the part number currently selected.

            {

        descField.rawValue = partDesc[i];          // Put the description in the description field

              itemPrice.rawValue = partPrice[i];          // and put the unit price in the unit price field.

              break;                                                                                // No need to go further if there is a match.

            }

   }

}

Thanks in advance

Avatar

Level 10

Hi,

I am not aware of any restriction, but 2,794 sounds like an awful lot.

Niall

Avatar

Level 1

I know it is a lot.

Is there a way that I can call the array frrom a data connection? I am sorry I am not a pro with the program.

Avatar

Level 10

Can you break the collection down into groups and then deal with multiple dropdowns, rather than trying to get it all within a single dropdown.

Having so many items in a dropdown seems to be difficult for the user in navigating the list.

Data connections would be another approach (either to a database or web service), but if the user has Reader, then the form would need to be Reader Enabled with the server component LC Reader Extensions ES3 or below.

Niall

Avatar

Level 1

Oh regarding the drop down box, I changed that to a text frield. So users enter the codes and the description and price populate automatically.