Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

Automatically Populating a field

Avatar

Level 4

How do I set up a field to automatically populate based on the enter in a previous field?  Example: Choose an employee name -- Automatically display manager name.  Thanks!

1 Accepted Solution

Avatar

Correct answer by
Former Community Member

There was nothing wrong with your code. I added a default case for testing so you may want to remove it. In your DDList you can have a value that you display and a value that you sbmit. This is common for DDlists. If you look at the binding tab you will see that the values are not the same. So the rawValue property will give you what is submitted and the formattedValue property will give you what is displayed. I simply modified your code to use the formattedValue and it works. You may want to fix the DDlist becaus eit is still set to submit a numeric value instead of the Name that the user selects.

I have attahend the modified sample

Paul

View solution in original post

12 Replies

Avatar

Former Community Member

Where is the information about the relationship between employee Name and manager name going to come from? Is this informaton stored in a database somewhere? An LDAP server?

Paul

Avatar

Level 4

The info is in an Excel file right now and since it's a relatively small amount of info it's in two unlinked dropdown boxes, in LC.  Is there a preferred place to have it or any way to just link the two fields?

Avatar

Former Community Member

I assume that you want to enter user name into one field and have the Manager field updated to reflect who the user's manager is (is this what you mean by linked).

If so then the information is in that Excel spreadsheet and the form woudl have to interrogate the spreadsheet to get the information. You can make the SS look like a DB and we can connect to it from the form but it will mean that we will have to extend the form to allow Reader users to make the DB call. Acrobat users do not have to worry about this. Also the SS woudl have to be available to every user (so that we can do the lookup) as well we would have to configure a Data Set Name (DSN) on each user machine. So it is possible but if you have a lrge number of users the maintenance can be a pain!

Paul

Avatar

Level 4

Ok, so this is sounding like a lot of work.  I could put the data in a DB, that's not an issue.  Is it something that even after we'd get it set, someone could access if they're away from the office not directly logged into the computer, just doing something web-based?  There's no way to manage the info with LC then?

Avatar

Former Community Member

You could hard code it into the form or you coudl make a web service to call the data (but th eweb service will havethe same Reader Extensions provisions). Hard coding it in the form woudl mean that the form woudl have to be updated each time the information changes.

Paul

Avatar

Level 4

How do I do the hardcoding? It's not that much to update and sounds simpler, or at least more self-contained in the long run.


Avatar

Former Community Member

There are two coding techniques you can use to do this. Before we get to the coding the technique that will be used is to put code on the exit event of the field where the employee enters their name. The code would check to see what was entered and based on that value will update the Manager field with the correct name. This can be accomplished by using a series of IFstatements or if there are a large number of entries a SWITCH statement might be easier. I created a quick sample to show you how it is done for both.

Paul

Avatar

Level 4

I'm getting close to this working, but not quite.  I select the name for the Employee Name, but nothing appears in the Supervisor Name field.  I've attached a sample of what I'm doing.  There are more names involved, but I'm figuring that if I can get a few names to work, I can copy for the others.  Thanks so much for your help.

Avatar

Correct answer by
Former Community Member

There was nothing wrong with your code. I added a default case for testing so you may want to remove it. In your DDList you can have a value that you display and a value that you sbmit. This is common for DDlists. If you look at the binding tab you will see that the values are not the same. So the rawValue property will give you what is submitted and the formattedValue property will give you what is displayed. I simply modified your code to use the formattedValue and it works. You may want to fix the DDlist becaus eit is still set to submit a numeric value instead of the Name that the user selects.

I have attahend the modified sample

Paul

Avatar

Level 4

Thank you so much for your help!

Avatar

Level 4

To expand on this, how would one code this example so that if user selects Canada for Field1,  Field2 presents a drop-down list of provinces, but if US is selected for Field1  then Field2  populates with states?  Is there any way to accomplish this with hard code without resorting to a database?  Thank you.

Avatar

Former Community Member

Under your Designer ES installation you should have a sample file named "Purchase Order.pdf" that contains the drop-down sample you are looking for (Canada / US / Provinces / States).

With my installation it was found under: C:\Program Files (x86)\Adobe\LiveCycle ES\Workbench ES\Designer ES\8.2\EN\Samples\Forms\Purchase Order\Dynamic Interactive\Forms\

And if you have trouble finding it, it's attached to this message.

The following has evaluated to null or missing: ==> liqladmin("SELECT id, value FROM metrics WHERE id = 'net_accepted_solutions' and user.id = '${acceptedAnswer.author.id}'").data.items [in template "analytics-container" at line 83, column 41] ---- Tip: It's the step after the last dot that caused this error, not those before it. ---- Tip: If the failing expression is known to be legally refer to something that's sometimes null or missing, either specify a default value like myOptionalVar!myDefault, or use <#if myOptionalVar??>when-present<#else>when-missing. (These only cover the last step of the expression; to cover the whole expression, use parenthesis: (myOptionalVar.foo)!myDefault, (myOptionalVar.foo)?? ---- ---- FTL stack trace ("~" means nesting-related): - Failed at: #assign answerAuthorNetSolutions = li... [in template "analytics-container" at line 83, column 5] ----