Expand my Community achievements bar.

SOLVED

Populate Field from Concatenated Values Issues

Avatar

Former Community Member

I am trying to set a value on a read only/calculated text field based on the exit event of another field, below is what I'm using,

but nothing happens when I enter data and exit the field.

Year0 is a hidden calculated field set to current year in a 4 digit format.

Using JavaScript - any ideas where I'm going wrong?  Thank you!

var

myVA = form1.#subform[0].#subform[1].#subform[2].Table1.Row1.tVANo.rawValue;

var

myYR = form1.#pageSet[0].Page1.Year0.rawValue;

var

myPrj = this.rawValue;

myVA

= Concat(myPrj, "-", myYR)

1 Accepted Solution

Avatar

Correct answer by
Level 10

Glad we are getting closer

Okay, if you are undertaking a calculation and you want the answer to appear in the tVANo field, it would make sense to have the script in the calculate event of the tVANo field.

Once you have declared and set the values of myYR and myPrj, you can then set the rawValue of the tVANo field by refering to it as "this".

You don't need the myVA variable at all.

So, this in the calculate event of the tVANo field:

var myYR = form1.sfrmMain.Year0.rawValue;

var myPrj = form1.sfrmMain.sfrmMainSub1.sfrmMain2.tbMainInfo.Row2.tPrjNo.rawValue ;


this.rawValue = myPrj.toString() + "-" + myYR.toString();

As I said, you may not need the .toString(), so the script could look like:

var myYR = form1.sfrmMain.Year0.rawValue;
var myPrj = form1.sfrmMain.sfrmMainSub1.sfrmMain2.tbMainInfo.Row2.tPrjNo.rawValue ;


this.rawValue = myPrj + "-" + myYR;

I hope that helps,

Niall

View solution in original post

10 Replies

Avatar

Level 10

Hi,

A couple of things:

Concat is a FormCalc function. In JavaScript you would add (+) the two objects' rawValues. You may need to convert them to strings first - .toString().

Secondly you don't seem to be doing anything after you concatenate the two objects (???).

Lastly you seem to have a few unnamed subforms, which may cause the references to fail. See how to reference objects here: http://assure.ly/kUP02y (and the pitfalls in not naming objects and subforms).

A good debugging tip is to open the JavaScript Console (Control+J) and then insert a line in your script to write a variable out to the console. For example add this after you declare and set myVA:

console.println("This is myVA: " + myVA); 

If you get to declare the variable correctly, then the following JavaScript may work

myVA = myPrj.toString() + "-" + myYR.toString(); 

You may not need the .toString(), it depends on what the original objects are. Try without it first.

Hope that helps,

Niall

Avatar

Former Community Member

Thank you, yes, it helps alot.  I sure did get FormCalc and JavaScript mixed  up.  Checked out the link and renamed subforms.  I had ended up adding them on  the fly as my floating text field was greyed out and it was the only way I could  find to get things to layout on the page the way I needed, and need to learn to  name them.  I'm not understanding the JavaScript Console part, when I press  ctrl/J, nothing happens, so not sure where I should be or how to accomplish  this.  I agree my referencing is probably wrong.  I got the 'address' by  clicking into the field(s) and copy/pasting the address listed at the top, but  that might not be the right way to go.  Below revised is still not working - I  thought myVA = myPrj.toString() + "-" + myYR.toString(); would have  been how to tell the tVANo field to be that value when it happened on the exit  event of tPrjNo.  Am used to Access, where I can just say me.fielda = me.fieldb  or whatever value, so I need to learn how to do same in JavaScript.  What is the  right way to tell the tVANo to be whatever they enter in the tPrjNo field PLUS  the current year in 4 digit format.  Thank you very much, Cathy

var myVA = form1.sfrmMain.sfrmMainSub1.sfrmMain2.tbMainInfo.Row1.tVANo.rawValue;

var myYR = form1.#pageSet[0].Page1.Year0.rawValue;

var myPrj = this.rawValue;

myVA = myPrj.toString() + "-" + myYR.toString();

Avatar

Level 10

Hi Cathy,

Before we get to joing the two variables, I think that it is important to declare hte variables first.

The JavaScript Console is very powerful tool for debugging. You can access when previewing your form in LC Designer or when you open your form in Acrobat.

The console is not available in Reader.

It will show up errors as you interact with your form. This will give you some direction to resolving the issue back in LC Designer.

Javascript Console.png

If you can't get Control+J to work, then you could use this line after the variable is declared:

xfa.host.messageBox(myVA); 

If you have a look at page 3 of the SOM Expression form, you will see a shortcut to referencing objects (also in video, sorry about the audio).

Using the Control+Click to reference objects will help, as LC Designer will resolve the node of the object if necessary. This would happen if there are unnamed objects/subforms, there are multiple objects with the same name; or if you have named an object using a reserved word.

So, I would be inclined to get this sorted first and then concentrate on merging the two variables. For example, is Row1 set to repeat?

Niall

Avatar

Level 10

Also, looking at your script I would say that the Year0 object is on the Master Page and therefore if the script is in an object on the Design pages, then you will definitely need to resolve the node (see examples on xfa.resolveNode).

Using Control+Click will do this for you automatically.

Niall

Avatar

Former Community Member

So sorry, Niall, I am not with you at all, and am seeing I'm very lacking in the basics.  When you say to use Control+Click, could you please explain more about what this means and how to do it? Tried ctrl/clicking in several places, both in preview and designer, not sure what is supposed to happen.

Got the JavaScript debugger console up, thank you, that helped, though am still not sure how to use it, but at least I can get to it.  It did come up with one error where I had tried something before and forgot to delete it where I was mixing up FormCalc and JavaScript on the concat function, and I removed that, I had been trying to do a calculation directly on the tVANo field instead of exit event of tPrjNo.

I added below after the variable is declared, but nothing happened when I tested in preview and exited the tPrjNo, so I'm sure I'm not referencing it right, but am not understanding what you'r trying to tell me about how to get there.  I went to page 3 of the SOM Expression form, but am staring blankly at it, again, my apologies for being slow to grasp this.  Thank you for your patience and help, Cathy

xfa.host.messageBox(myVA); 

Avatar

Former Community Member

I've moved Year0 to the form page, it's a hidden field, so wasn't necessary to have it on master page if that helps.

Still not seeing how to use control+click, thank you again.

var myYR =  form1.sfrmMain.Year0.rawValue;

Avatar

Former Community Member

Hopefully the references may be correct now, I entered them in the JavaScript editor and made sure to enter manually and check that at each dot . the proper name came up next till it gave me the .rawValue selection, here is where I'm at now.  I am still working on finding out how to use control + click.

var myVA = form1.sfrmMain.sfrmMainSub1.sfrmMain2.tbMainInfo.Row1.tVANo.rawValue;
var myYR = form1.sfrmMain.Year0.rawValue;
var myPrj = form1.sfrmMain.sfrmMainSub1.sfrmMain2.tbMainInfo.Row2.tPrjNo.rawValue;

myVA = myPrj.toString() + "-" + myYR.toString();

Avatar

Former Community Member

Update - I was using the field's exit event instead of calculate  (JavaScript) and now this code is entering the value of tPrjNo + - 4  Digit Year in the tPrjNo field instead of tVANo field. Getting closer,  you were right about the references not being right.  Now, hopefully it  is just the code that needs help.

var myVA = form1.sfrmMain.sfrmMainSub1.sfrmMain2.tbMainInfo.Row1.tVANo.rawValue;
var myYR = form1.sfrmMain.Year0.rawValue;
var myPrj = form1.sfrmMain.sfrmMainSub1.sfrmMain2.tbMainInfo.Row2.tPrjNo.rawValue;


myVA = myPrj.toString() + "-" + myYR.toString();

Avatar

Correct answer by
Level 10

Glad we are getting closer

Okay, if you are undertaking a calculation and you want the answer to appear in the tVANo field, it would make sense to have the script in the calculate event of the tVANo field.

Once you have declared and set the values of myYR and myPrj, you can then set the rawValue of the tVANo field by refering to it as "this".

You don't need the myVA variable at all.

So, this in the calculate event of the tVANo field:

var myYR = form1.sfrmMain.Year0.rawValue;

var myPrj = form1.sfrmMain.sfrmMainSub1.sfrmMain2.tbMainInfo.Row2.tPrjNo.rawValue ;


this.rawValue = myPrj.toString() + "-" + myYR.toString();

As I said, you may not need the .toString(), so the script could look like:

var myYR = form1.sfrmMain.Year0.rawValue;
var myPrj = form1.sfrmMain.sfrmMainSub1.sfrmMain2.tbMainInfo.Row2.tPrjNo.rawValue ;


this.rawValue = myPrj + "-" + myYR;

I hope that helps,

Niall

Avatar

Former Community Member

Everything is working great now, thank you, that did the trick!  For info, below is the final one I used, it worked great. I had been trying to use the exit event of the tPrjNo field, and when I changed to calculated, I still had put the code on the tPrjNo field, but just now in reading your reply, it hit me this needed to go on the tVANo field . . .  what a difference, thank you sooooo much for your patience and help.

var myYR = form1.sfrmMain.Year0.rawValue;
var myPrj = form1.sfrmMain.sfrmMainSub1.sfrmMain2.tbMainInfo.Row2.tPrjNo.rawValue ;


this.rawValue = myPrj.toString() + "-" + myYR.toString();