NetTalk Central

Author Topic: Count Records in a Drop Down  (Read 3763 times)

trent

  • Full Member
  • ***
  • Posts: 204
    • View Profile
    • Email
Count Records in a Drop Down
« on: February 14, 2012, 03:58:49 PM »
I am trying to show or hide a drop down field on a NetWebForm depending on the results of the drop down field when the drop down field is reset by a user selecting a date from a Date field on the form. I would like to hide the drop down field if the result count is less than 1.

Does anyone know how to do this?

kevin plummer

  • Hero Member
  • *****
  • Posts: 1195
    • View Profile
    • Production Accounting and Software Payroll
Re: Count Records in a Drop Down
« Reply #1 on: February 14, 2012, 06:36:21 PM »
I think you need to work out how many records would appear in the drop down in SS code after a date is selected. I do a similar thing but only show the drop down if more than 1 record. So I just loop the file and if my counter hits 2 records break and set an SSV and use this as the basis for hiding/unhiding the control.

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11244
    • View Profile
Re: Count Records in a Drop Down
« Reply #2 on: February 14, 2012, 10:44:23 PM »
Hi trent,

I'm not sure how much detail you need, but Kevin's answer is right.

let's cover the bases for hiding a field though;
a) set the "HIDE IF" setting for the dropdown, based on some Session value. for example;
p_web.GetSessionValue('recs') = 0

b) In the date field, add the drop-down to the "reset list" on the "client side" tab

c) In the Validate::Fieldname routine for the date field, calculate the number of records there would be in the dropdown (well, calculate if there are any recs) and set the same session value appropriately. For example
p_web.SetSessionValue('recs',1)

Cheers
Bruce

trent

  • Full Member
  • ***
  • Posts: 204
    • View Profile
    • Email
Re: Count Records in a Drop Down
« Reply #3 on: February 19, 2012, 05:49:13 PM »
Hi Kevin and Bruce,

Thank you for your replies, I don't think my question was very clear... setting a session value to hide the drop down is the easy part, what I need to know is how to count the results that are in the drop down after the drop down has been reset by the date field.

The drop down has an OptionFilter embed using prop:filter to select records from a table. Where are these results stored and how does one count them?

kevin plummer

  • Hero Member
  • *****
  • Posts: 1195
    • View Profile
    • Production Accounting and Software Payroll
Re: Count Records in a Drop Down
« Reply #4 on: February 19, 2012, 06:16:25 PM »
Hi Trent "I think" the problem is that this information (# records) is not available until the drop list is reset and at that point it is too late to set a ssv and hide the control. Looking at the source it appears as though there is only really one place to stick some embed code and do some testing.

  ! [Priority 5000]

  ! End of "Option Filter & Order"

Failing that, you may have to do your own loop to test # records as previously suggested.

trent

  • Full Member
  • ***
  • Posts: 204
    • View Profile
    • Email
Re: Count Records in a Drop Down
« Reply #5 on: February 19, 2012, 06:54:59 PM »
Hi Kevin,

You are correct, the information isn't available until *after* the drop list has been reset. I am using an SQL database so what I have done is run a 'select count(*)' script in the Validate::FieldName embed for the Date field and set the 'recs' SSV = to 1 if records are found. The drop down is then reset and unhidden if there are records.

Thank you for your help.