Expand my Community achievements bar.

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

Getting CURRENT record DURING population

Avatar

Former Community Member

I've made an xdp whose fields match an xsd. Now if the xml that populates the form looks like this:

<a>

  <a1>1000</a1>

  <a2>credit</a2>

<a>

<a>

  <a1>1400</a1>

  <a2>debit</a2>

<a>

...I would like the data in field a1 to be preceded by a minus-sign IF and only if a2 for the same record equals the string "credit".

The problem is that I cannot seem to get a hold of the record pointer/current record during population. I'm looking for something along the (js-)lines of:

a1::someEvent

if ($record.a2 === "credit") this.rawValue = "-" + $record.a1;

I'm looking for a 'hygienic' solution that doesn't involve dumping a2 into a hidden field.

Any clues?

1 Accepted Solution

Avatar

Correct answer by
Level 10

Hi,

If you have a field bound to element a1 then you can use the dataNode property to reference the bound value, so dataNode.parent.a2.value will reference the "credit" / "debit" value, so in the calculate event you could have;

if (this.dataNode.parent.a2.value === "credit")
this.rawValue = "+"+this.rawValue;
else
this.rawValue = "-"+this.rawValue;

This might be a problem when you submit the form so an alternative would be to update the display picture and display a "+" or "-" literal, maybe in the docReady event.

if (this.dataNode.parent.a2.value === "credit")
this.format.picture.value = "num{'+'z,zz9.99}";
else
this.format.picture.value = "num{'-'z,zz9.99}";

Good luck

Bruce

View solution in original post

9 Replies

Avatar

Level 2

This code works in the form:ready event:

if (this.a2.rawValue == "debit")

{

var val = parseInt(this.a1.rawValue);

val = val * -1;

this.a1.rawValue = val.toString();

}

Terry

Avatar

Former Community Member

I might have been a bit fuzzy in my first post, but there are no fields named a1 and a2. Just xml tags. There is however one field that holds the data of a1, which should be negative if the corresponding xml records a2 equals "credit".

I don't want to write stuff into hidden fields, meaning I'd like to solve it without the value of a2 ever entering the form.

Avatar

Correct answer by
Level 10

Hi,

If you have a field bound to element a1 then you can use the dataNode property to reference the bound value, so dataNode.parent.a2.value will reference the "credit" / "debit" value, so in the calculate event you could have;

if (this.dataNode.parent.a2.value === "credit")
this.rawValue = "+"+this.rawValue;
else
this.rawValue = "-"+this.rawValue;

This might be a problem when you submit the form so an alternative would be to update the display picture and display a "+" or "-" literal, maybe in the docReady event.

if (this.dataNode.parent.a2.value === "credit")
this.format.picture.value = "num{'+'z,zz9.99}";
else
this.format.picture.value = "num{'-'z,zz9.99}";

Good luck

Bruce

Avatar

Former Community Member

Nice find Bruce! Works like a charm!

I thought I know the XFA specs pretty well, but how on earth did you find out about using dataNode as a property of this? According to my understanding, it shouldn't even exist (and doesn't from what I've seen in the XFA specs).

It seems that regardless of what event I'm hooking into, the render engine calls the script an extra time on an empty record, resulting in an error (that a2 is null). It's easy enough to filter the occurence out by doing:

var n = this.resolveNode("dataNode.parent.a2");
if (n !== null && n.value === "credit")  { ... }

Although I'm still curious as to why...

Avatar

Level 10

Hi,

I forgot it wasn't documented, it is mentioned in the http://partners.adobe.com/public/developer/en/xml/Adobe_XML_Form_Object_Model_Reference.pdf document but only in the examples.  So think it is safe to use (and wont be dropped in a future release) ... at least I've used it a lot.

I have noticed an extra empty record being processed at times but I didn't have that problem this time, haven't found a pattern either, just tried it in Designer ES2 preview mode using Reader X and it was ok.

Sometimes I would love to see the Reader source code.

Glad to be able to help.

Bruce

Avatar

Former Community Member

Hi again Bruce,

I've searched through the XML Form Object Model Reference you linked to, but still cannot find any references to an object called 'dataNode'. I'm thinking another official approach would be to access the dataWindow object, which should keep track of the current record. Alas...

Avatar

Level 10

I see what you mean, am sure I've seen it somewhere but at the moment can only find it in one of John Brinkman's examples, so have asked him if it is supported, http://blogs.adobe.com/formfeed/2008/10/data_binding_with_predicates.html.

Lets hope, Bruce

Avatar

Level 10

Looks like we are good to go with the dataNode property.  This is the response from John Brinkman,

     As far as I’m concerned, the dataNode property should be documented and reliable. I’ll log a bug.