11/22/2024 10:51:44 PM
|
|
slxdeveloper.com Community Forums |
|
|
|
The Forums on slxdeveloper.com are now retired. The forum archive will remain available for the time being. Thank you for your participation on slxdeveloper.com!
Forum to discuss usage & tips for SalesLogix controls and other 3rd party ActiveX controls. View the code of conduct for posting guidelines.
|
|
|
|
Lookup Control - getting the ID not the Display Text
Posted: 03 Dec 06 8:10 PM
|
fiogf49gjkf0d When you create a Lookup Control on a Data Form in Architect, you set the LookupID property of the control to the column where the Identifier of the selected Lookup Record will get stored. You set the Text property of the control to the column where the text to display to the user for the selected Lookup Record is stored.
On the Change Event of my Lookup Control, I'd like to access the ID NOT the Text. I've looked through all the Properties of the Control : lkpControl.Text returns the display value, not the value that gets stored into the LookupId column. How can I get at that ID?
The article at http://www.slxdeveloper.com/page.aspx?id=35&articleid=75 describes how to instantiate a Lookup using LookupItemWithConditionByID - I already have my Lookup Control on the form - I don't think I want to instantiate one on the fly (unless I have to in order to get at the ID).
I've stumbled across some code that uses GetPropertyOf("luAccount", "LinkID") but this does not work in my script - I get an error (this is probably only valid in Legacy Scripts, correct?)
Any Help would be MUCH appreciated! |
|
|
| |
|
Re: Lookup Control - getting the ID not the Display Text
Posted: 03 Dec 06 11:34 PM
|
fiogf49gjkf0d Ryan - thanks for the response. It's interesting - I tried using .LookupId, and it returned a blank value. Turns out it's Blank when called by the OnChange event triggered by AXFormCreate(Sender)! When the User actually changes the value in the control by clicking on the lookup it it does return a value.
I basically need the Id to retrieve and display the value of other columns in the Lookup Table. For instance, if the Lookup Id is on WidgetId, the Lookup Display Text is on WidgetName, and I want to show another field on my form, say WidgetPrice.
I tried making the WidgetPrice txt control bound to the Column in the Lookup Table and paradoxically it displays when the form is loaded but not when the user changes the value in the Lookup.
Any way for me to get the LookupId on load of the form so I can fill in other fields with values based on the Id? Or should I bind the other fields in some special way? Or should I completely hack it and do both?! |
|
|
|
Re: Lookup Control - getting the ID not the Display Text
Posted: 04 Dec 06 3:23 AM
|
fiogf49gjkf0d Let me try to answer your question(s):
First of all, I would make sure that the Lookup itself returns both the ID and the Text of the selected Item.
Now, the easiest way to accomplish this is to create fields on the Form's table to store the ID (Bind the lookupID), Text(Bind the Text field) and addtl fields each bound to controls that you would populate based on the lookup's result. This way, once you write them and save the record they are committed to the DB. On this case, I would just add a script on the PopupReturn event of the lookup to set all addtl fields to the appropriate values.
Otherwise, if you only want to track the ID of the field, I would only bind the Lookup ID and then just have code on the Form Change event to populate the addtl fields, including the Lookup Text. This same code should be invoked on the PopupReturn event if the LookupID has changed.
|
|
|
| |
|
Re: Lookup Control - getting the ID not the Display Text
Posted: 04 Dec 06 1:15 PM
|
fiogf49gjkf0d Thanks for everyones feedback, it's been a big help! Here's how things finally ended up:
The Problem: An Add/Edit Data Form called from a Grid has a Lookup on it. The selection in the lookup (Sale Code Text, Sale Code Id) is used to populate a read-only text control (Discount Percent) with another value from the lookup table. This is then used to recalculate some math for another field (Total Price) on the form.
If the field Discount Percent is bound to the Lookup Table directly, it does not get refreshed when the selection in the Lookup is changed. It does, however, get populated when the Form Loads.
If the field Discount Percent is not bound to anything, just a text control, and the user Edits a record, the On Change event for the Lookup Control fires BEFORE the On Change event of the Form. The Lookup Id returns a blank until the On Change of the Event fires even though there is a record selected! You cannot get at the Lookup Id until the Form On Change event fires. We CANNOT call the recalculate for Total Price until the Form On Change, and we preferrably only call it until once user actually changes the selected item in the Lookup.
The Solution: - Create a module level variable called m_bFormLoading. Set it to TRUE in AXFormCreate(Sender). - Set this variable to FALSE in AXFormChange(Sender) - In the On Change events of all Controls used by the Recalculate Routine, only call Recalculate if the m_bFormLoading is FALSE. - Use the Lookup Id to put data into the Discount Percent within the Form OnChange event, and in the Lookup OnChange event if the Form is NOT Loading.
If anyone wants to see the code let me know... |
|
|
|
Re: Lookup Control - getting the ID not the Display Text
Posted: 04 Dec 06 1:29 PM
|
fiogf49gjkf0d In 6.2.3 there were some new form properties added so you can now monitor what is happening at the time the event occurs, achieving the same thing you describe but without the need for the global variable.
IsReading - means the data binding system is currently "active" IsValidating - validate event is currently being evaluated/run IsWriting - data is being saved to the DB Modified - an edit has been made to the value of a data bound control
You could do something like this:
If Not IsReading ' do something here id = lookupedit1.Lookupid End If
The point or purpose of these new properties are so you can distinguish between events firing from data binding and from user initiated actions.
-Ryan |
|
|
|
You can
subscribe to receive a daily forum digest in your
user profile. View the site code
of conduct for posting guidelines.
Forum RSS Feed - Subscribe to the forum RSS feed to keep on top of the latest forum activity!
|
|
|
|
|
|
|
|