Expand my Community achievements bar.

Guidelines for the Responsible Use of Generative AI in the Experience Cloud Community.

Changing table values in a for Loop

Avatar

Level 2

Hello,

        I am basically as SAP Technical consultant and working on Adobe Forms, I am struggling a bit with the syntax as couple of the JAVA script statements don't seem to work. Could any one please help/guide me as to how can I change the values at run time in the loop? Based on the user input I have to re sequence a certain field of the table, I am assiging the value but it doesn't work.

var re_seq_flag = " "; // Re-Sequence Flag

    for (var nItemCount = 0; nItemCount < nItemsLength; nItemCount++) { // Begin Loop T_ELEMENTS after the Instance is created

    var old_row_id = sub_T_ELEMENTS.ROW_IID.rawValue;

    var new_row_id = oItems.nodes.item(nItemCount).ROW_IID.value;

if ( oItems.nodes.item(nItemCount).ROW_IID.value == null) {

re_seq_flag

= "X";

new_row_id

= parseFloat(sub_T_ELEMENTS.ROW_IID.rawValue) + parseFloat(1);

oItems.nodes.item(nItemCount).ROW_IID.value

= new_row_id; // This statement does not work

xfa.host.messageBox("New Row added "

else {

if ( re_seq_flag == "X") {

temp_index

= parseFloat(oItems.nodes.item(nItemCount).ROW_IID.value) + parseFloat(1);

oItems.nodes.item(nItemCount).ROW_IID.value

= temp_index; // This statement does not work

// xfa.host.messageBox("After Re-Seq " + oItems.nodes.item(nItemCount).ROW_IID.value);

}

}

}

In the above code where in I am trying to assign the value back to table field fails, am I using the correct syntax? Could anyone help me please?

+ oItems.nodes.item(nItemCount).ROW_IID.value);

}

+ oItems.nodes.item(nItemCount).ROW_IID.value);

}

else {

if ( re_seq_flag == "X") {

temp_index

= parseFloat(oItems.nodes.item(nItemCount).ROW_IID.value) + parseFloat(1);

oItems.nodes.item(nItemCount).ROW_IID.value

= temp_index; // This statement does not work

// xfa.host.messageBox("After Re-Seq " + oItems.nodes.item(nItemCount).ROW_IID.value);

}

}

}

In the above code where in I am trying to assign the value back to table field fails, am I using the correct syntax? Could anyone help me please?

10 Replies

Avatar

Level 2

There has been repeation above, please ignore the duplicate statments.

Avatar

Level 10

Hi,

I'm trying to follow the script. The one thing I would query is what are the objects that you are trying to access their values?

When reading/writing the value of an object, you use '.rawValue'.

When reading/writing to a Global Variable (set initially in the File > Form Properties > Variables tab), you would use '.value'.

When dealing with script variables you do not need to specify .value, you just use the variable name.

So in your script if you are trying to access the value of objects, use '.rawValue' .

Good luck,

Niall

Avatar

Level 2

Hi,

    Please correct me if I am wrong, I am using .value when I am addressing a table field in loop, as there is no field on the form it is bound to, my usnderstanding is that .rawValue is feature/attribute which is specific to fields which are available on the form. A table available in the interface as is bound, but not all the fields. The fields which are not bound, can be addressed with key word .value .

The situation when the below code is used:-

1. There are + and - buttons on the form, which are used to create an instance for subforms. which are bound to tables.

2. Once the instance is created, the table should re-sequenced and should assign value to the new instance in table. This field in not bound.

How can I achieve this?

Regards,

Shishir.P

Avatar

Level 10

Hi Shishir.P,

The use of .value/.rawValue does not relate to whether an object is bound or not.

If you are trying to access the value of an object (in JavaScript), then you need to use .rawValue.

You would use .value for a global variable, or an attribute of an object, like the font colour.

I think that when you use .rawValue, you will have more success.

Also when debugging, open the JavaScript Console (press Control+J) when previewing the form and when you interact with the form any errors should show up there.

Good luck,

Niall

Avatar

Level 2

Hi Niall,

          I am trying to do what you suggested, if you take look at below script:-

         

var

oItems = xfa.resolveNode( "xfa.record.HAP_DOCUMENT.T_ELEMENTS" );

var

nItemsLength = oItems.nodes.length;

if

(flag == "1"){

flag

= "0";

     for (var nItemCount = 0; nItemCount < nItemsLength; nItemCount++) { // Begin Loop 1

     if (oItems.nodes.item(nItemCount).ROW_IID.value == row_id) {

     }

In the loop .value returns the value held at the runtime by the table field, which I compare, but when I try to do the same with .rawValue, I get a null. Could you help me with a reason?

Regards,

Shishir

Avatar

Level 10

Hi Shishir,

Going through the script again:

var oItems = xfa.resolveNode( "xfa.record.HAP_DOCUMENT.T_ELEMENTS");

var nItemsLength = oItems.nodes.length;

if (flag == "1")

{

     flag = "0";

     for (var nItemCount = 0; nItemCount < nItemsLength; nItemCount++)


     { // Begin Loop 1


          if (oItems.nodes.item(nItemCount).ROW_IID.value == row_id)

          {

          ...

          }

     }

}

The testing the record (oItems.nodes.item(nItemCount).ROW_IID), using .value should work to access the value of the node. However what is 'row_id'? Is this an object? if it is, then you would need row_id.rawValue.

Does that work?

Niall

Avatar

Level 2

Hi Niall,

          As you mentioned that .value should be used for the global fields, so in the script below I am addressing the table which is at global level;-

var oItems = xfa.resolveNode( "xfa.record.HAP_DOCUMENT.T_ELEMENTS" );

var nItemsLength = oItems.nodes.length;

In the above script the T_ELEMENTS is a table which available globally and is a part of the interface to the Adobe form; when looping as you mentioned I have to use the property .value to retrieve the values from the table fields. How would I be able to change them or overwirte them? The below statement when used in the script fails:-

temp_index

= parseFloat(oItems.nodes.item(nItemCount).ROW_IID.value) + parseFloat(1);

oItems.nodes.item(nItemCount).ROW_IID.value

= temp_index;

The variable temp_index which is newly calculated index number is not able to overwrite the table table field ROW_IID which is part of table T_ELEMENTS, could you please suggest?

Regards,

Shishir.P

Avatar

Level 2

Hi Niall,

       Sorry Niall .... I guess we were writing at the same time. Row_ID is variable which stores the value in one of the hidden fields which I use for the comparison purpose .... The actual script is as below;-

var

oItems = xfa.resolveNode( "xfa.record.HAP_DOCUMENT.T_ELEMENTS" );

var

nItemsLength = oItems.nodes.length;

var

flag = this.parent.parent.parent.parent.Storage_Form.Add_Row_Flag.rawValue;

var

row_id = this.parent.parent.parent.parent.Storage_Form.ROW_IID.rawValue;

if

(flag == "1"){

flag

= "0";

for (var nItemCount = 0; nItemCount < nItemsLength; nItemCount++) { // Begin Loop 1

if (oItems.nodes.item(nItemCount).ROW_IID.value == row_id) { // ROW_IID VAlue

}

Yes ...... it does work ..... while I trying to compare ..... it is just that I cannot overwrite the same using

.value.

The form is bit complicated and I was hoping if I could show you, so that you have better understanding about the same? Can I send you the same?

Regards,

Shishir.P

Avatar

Level 10

Hi Shishir,

Its difficult to see the structure and check the syntax without it. If you upload it to Acrobat.com and either share the published link here or send me a pm.

We will be able to get it sorted,

Niall

Avatar

Level 2

Hi Niall,

             I sent you a private message on your Adobe ID, could you please check the same? I will waiting your reply.

Regards,

Shishir.P