New call-to-action
Results 1 to 19 of 19

Thread: Increment a repeating field by one on double click

  1. #1
    Member J.R. Noe's Avatar
    Real Name
    J.R. Noe
    Join Date
    Feb 2011
    Location
    Brandenburg, KY.
    Posts
    417

    Default Increment a repeating field by one on double click

    I want to be able to enter a 9 digit number in a textbox in the first record in a repeating section, and then when i double click the next record i want it to increment the value by one from the previous record.

    further down the road i would want to do a sql lookup to find the last number used for that particular substance based on the department logged in and the substance being entered. But for now i would be happy to double click to add the values.

  2. #2
    "Certified" Alphaholic
    Real Name
    Gregg Schmidt
    Join Date
    Mar 2001
    Location
    Milwaukee
    Posts
    1,496

    Default Re: Increment a repeating field by one on double click

    Hi JR,
    why put it off when you can do it sooner?
    Just need the column names and table name
    to create sql code.

  3. #3
    Member J.R. Noe's Avatar
    Real Name
    J.R. Noe
    Join Date
    Feb 2011
    Location
    Brandenburg, KY.
    Posts
    417

    Default Re: Increment a repeating field by one on double click

    Thank you Greg.

    The table is called 'narcx_ordervials'
    The column I want to get the max number from is called 'narcbarcd'
    I want to filter the table by these columns: 'companyid', 'departmentid' and 'substanceid'
    companyid and departmentid have session variables (':coid' and ':depid') when a user logs in.

    Pulling it from a table and adding +1 to it might be difficult.
    Since these will be entered in a repeating section, usually 25 at a time, and it is not saved until all the records are in, how can it retrieve the correct last record?
    I had been working on retrieving the last/max number and add +1 to it for the first record in the repeating section, and then as it is entered it gets saved and when i click the next row it adds +1 to the number in memory and so on.
    Hope I explaining that correctly.
    Last edited by J.R. Noe; 03-25-2020 at 07:54 AM.

  4. #4
    "Certified" Alphaholic
    Real Name
    Gregg Schmidt
    Join Date
    Mar 2001
    Location
    Milwaukee
    Posts
    1,496

    Default Re: Increment a repeating field by one on double click

    The sql code is easy enough to generate.
    I'm sure what you want to do with the repeating section is doable,
    but far easier to get you a good answer if I have sample data and ux to work with.

    Code:
    select max(narcbarcd)+1 from narcx_ordervials
    where companyid = :coid and departmentid = :depid and substanceid = :substanceID

  5. #5
    Member J.R. Noe's Avatar
    Real Name
    J.R. Noe
    Join Date
    Feb 2011
    Location
    Brandenburg, KY.
    Posts
    417

    Default Re: Increment a repeating field by one on double click

    Here is what is have to get the next barcode to use. I put the number in a field on the parent form, now i just need to figure out how to double click, or populate the 20 to 25 records in the repeating section with incrementing numbers starting with this number.

    function setlastbarcode as c (e as p)
    dim Vstartingbarcode as c
    dim Vconsubstanceid as c
    dim Maxbarcode as n
    dim Vcoid as n
    dim Vdepid as n
    dim Vsubid as c
    Vcoid = e.dataSubmitted.companyid1
    Vdepid = e.dataSubmitted.departmentid1
    Vstartingbarcode = e.dataSubmitted.startingbarcode
    Vsubid = e.datasubmitted.ConSubstanceID
    dim cn as sql::Connection
    dim result as l = .f.
    result = cn.Open("::Name::conn")
    if result then
    dim sqlSelect as c
    dim args as sql::Arguments
    sqlSelect = "SELECT max(narcbarcd)FROM narcx_ordervials WHERE companyid = :newcoid AND departmentid = :newdepid AND ConSubstanceID = :newsubid"

    args.add("newcoid",Vcoid)
    args.add("newdepid",Vdepid)
    args.add("newsubid",Vsubid)
    result = cn.Execute(sqlSelect,args)
    if result then
    dim rs as sql::ResultSet
    rs = cn.ResultSet
    result = rs.nextRow()
    if result then
    Maxbarcode = rs.data(1)
    e._set.startingbarcode.value = Maxbarcode

    else
    setlastbarcode = "alert('Not Working');"
    cn.close()
    end if
    else
    setlastbarcode = "alert('could not select the table');"
    end if
    else
    setlastbarcode = "alert('could not connect to database');"
    end if
    end function

  6. #6
    "Certified" Alphaholic
    Real Name
    Gregg Schmidt
    Join Date
    Mar 2001
    Location
    Milwaukee
    Posts
    1,496

    Default Re: Increment a repeating field by one on double click

    Hey JR,

    I'm sure there's a way to do this with JavaScript, but that would be beyond my knowledge right now.
    This code should work using xbasic.
    Code:
    dim activeRo as n = val(e._repeatingSections.REPEATINGSECTION_1.activeRow)
    dim autoBarcode as n = val(e._currentRowDataNew.barcode[activeRo - 1])+1
    eval("e._set.barcode_a5instance"+alltrim(str(activeRo))+".value") = alltrim(str(autoBarcode))

  7. #7
    Member J.R. Noe's Avatar
    Real Name
    J.R. Noe
    Join Date
    Feb 2011
    Location
    Brandenburg, KY.
    Posts
    417

    Default Re: Increment a repeating field by one on double click

    That works great Gregg. Than you very much. Just what I needed.

    I just need to figure out how to set an "if" for when its on the first record.
    If i double click on the first record, it throws an error, but works great on any other record.

  8. #8
    "Certified" Alphaholic
    Real Name
    Gregg Schmidt
    Join Date
    Mar 2001
    Location
    Milwaukee
    Posts
    1,496

    Default Re: Increment a repeating field by one on double click

    What do you want it to do when you double click the first record ?

  9. #9
    Member J.R. Noe's Avatar
    Real Name
    J.R. Noe
    Join Date
    Feb 2011
    Location
    Brandenburg, KY.
    Posts
    417

    Default Re: Increment a repeating field by one on double click

    Probably want it to do nothing if its on the first record.

  10. #10
    "Certified" Alphaholic
    Real Name
    Gregg Schmidt
    Join Date
    Mar 2001
    Location
    Milwaukee
    Posts
    1,496

    Default Re: Increment a repeating field by one on double click

    Here you go.

    Code:
    dim activeRo as n = val(e._repeatingSections.REPEATINGSECTION_1.activeRow)
    dim autoBarcode as n = val(e._currentRowDataNew.barcode[activeRo - 1])+1
    
    if activeRo > 1 then
    	eval("e._set.barcode_a5instance"+alltrim(str(activeRo))+".value") = alltrim(str(autoBarcode))
    end if

  11. #11
    Member J.R. Noe's Avatar
    Real Name
    J.R. Noe
    Join Date
    Feb 2011
    Location
    Brandenburg, KY.
    Posts
    417

    Default Re: Increment a repeating field by one on double click

    That caused an error Gregg.
    er.jpg

  12. #12
    "Certified" Alphaholic
    Real Name
    Gregg Schmidt
    Join Date
    Mar 2001
    Location
    Milwaukee
    Posts
    1,496

    Default Re: Increment a repeating field by one on double click

    Sorry about that.
    Try this.
    Code:
    dim activeRo as n = val(e._repeatingSections.REPEATINGSECTION_1.activeRow)
    if activeRo > 1 then
    	dim autoBarcode as n = val(e._currentRowDataNew.barcode[activeRo - 1])+1
    	eval("e._set.barcode_a5instance"+alltrim(str(activeRo))+".value") = alltrim(str(autoBarcode))
    end if

  13. #13
    Member J.R. Noe's Avatar
    Real Name
    J.R. Noe
    Join Date
    Feb 2011
    Location
    Brandenburg, KY.
    Posts
    417

    Default Re: Increment a repeating field by one on double click

    Thank you Gregg, that took care of the error.
    It all works great now. I appreciate all your help.

  14. #14
    "Certified" Alphaholic
    Real Name
    Gregg Schmidt
    Join Date
    Mar 2001
    Location
    Milwaukee
    Posts
    1,496

    Default Re: Increment a repeating field by one on double click

    Glad to help.

  15. #15
    Member J.R. Noe's Avatar
    Real Name
    J.R. Noe
    Join Date
    Feb 2011
    Location
    Brandenburg, KY.
    Posts
    417

    Default Re: Increment a repeating field by one on double click

    Gregg, its working great, but now I am thinking of one more step to make it even better, lol.

    I put this code in to enter the next available barcode number in the first record record of the repeating section:
    if e.dataSubmitted.narcbarcd_A5INSTANCE1 = ""
    e._set.narcbarcd_A5INSTANCE1.value = Maxbarcode
    end if

    But now I'm thinking, how can i get it to cycle through ever how many records there are available in the repeating section and enter the barcodes without having to double click each record?
    I tried this code, and many versions of it, but it will put the next barcode in the second record but puts a "1" in all the rest of the records.

    var rows = {dialog.Object}._getRepeatingSectionRowCount('CONTAINER_5');
    for (var i = 1; i < rows+1; i++) {
    {dialog.object}.runAction('setNextBarcode');

    The 'setNextBarcode' is the code which is set on the double click to increment the barcode by 1.

  16. #16
    "Certified" Alphaholic
    Real Name
    Gregg Schmidt
    Join Date
    Mar 2001
    Location
    Milwaukee
    Posts
    1,496

    Default Re: Increment a repeating field by one on double click

    JR, I'm nowhere near as proficient with JavaScript as I am with xbasic.
    I was going to suggest auto-populating nextBarcode but thought you had
    your own reason(s) for not doing such a thing.
    As long as I'm asking, does the person doing the data entry need to know the
    barcode ? If not, you can do a loop after everything has been submitted.

    Some of this is easier to talk through instead of typing and waiting for a response.
    A phone call (and potentially screen sharing session) is so much more productive.

  17. #17
    Member J.R. Noe's Avatar
    Real Name
    J.R. Noe
    Join Date
    Feb 2011
    Location
    Brandenburg, KY.
    Posts
    417

    Default Re: Increment a repeating field by one on double click

    I hadn't really thought about auto-populating it, but after getting this far it just makes sense to do that.
    No, the data entry person doesn't have to know or see the barcode.
    A phone call would be fine.

  18. #18
    "Certified" Alphaholic
    Real Name
    Gregg Schmidt
    Join Date
    Mar 2001
    Location
    Milwaukee
    Posts
    1,496

    Default Re: Increment a repeating field by one on double click

    608-345-2697

  19. #19
    Member J.R. Noe's Avatar
    Real Name
    J.R. Noe
    Join Date
    Feb 2011
    Location
    Brandenburg, KY.
    Posts
    417

    Default Re: Increment a repeating field by one on double click

    Thank you Gregg Schmidt for solving this problem for me.

    Gere is how Gregg did it, for anyone interested in how to make this work.

    Here is the x-basic function that does all the work. It looks up to find the NEXT barcode to use and then auto generates the barcodes for ever how many records are in the repeating section.

    function setlastbarcode as c (e as p)
    dim Vstartingbarcode as c
    dim Vconsubstanceid as c
    dim Maxbarcode as n
    dim Vcoid as n
    dim Vdepid as n
    dim Vsubid as c
    Vcoid = e.dataSubmitted.companyid1
    Vdepid = e.dataSubmitted.departmentid1
    Vstartingbarcode = e.dataSubmitted.startingbarcode
    Vsubid = e.datasubmitted.ConSubstanceID
    dim cn as sql::Connection
    dim result as l = .f.
    result = cn.Open("::Name::conn")
    if result then
    dim sqlSelect as c
    dim args as sql::Arguments
    sqlSelect = "SELECT max(narcbarcd)FROM narcx_ordervials WHERE companyid = :newcoid AND departmentid = :newdepid AND ConSubstanceID = :newsubid"
    args.add("newcoid",Vcoid)
    args.add("newdepid",Vdepid)
    args.add("newsubid",Vsubid)
    Maxbarcode = sql_lookup(cn,"narcx_ordervials","companyid = :newcoid and departmentid = :newdepid and conSubstanceID = :newsubid","max(narcbarcd)",args)
    if Maxbarcode > 0 then
    e._set.startingbarcode.value = increment_value(Maxbarcode)
    for n = 1 to e.repeatingsectioninfo[1].totalrowcount
    Maxbarcode = increment_value(Maxbarcode)
    eval("e._set.narcbarcd_a5instance"+alltrim(str(n))+".value") = alltrim(str(Maxbarcode))
    next n
    else
    setlastbarcode = "alert('Not Working');"
    cn.close()
    end if
    else
    setlastbarcode = "alert('could not connect to database');"
    end if
    end function

Similar Threads

  1. Double click
    By Chuffy in forum Alpha Five Version 10 - Desktop Applications
    Replies: 2
    Last Post: 07-28-2010, 04:39 AM
  2. On Double click
    By Atta in forum Application Server Version 10 - Web/Browser Applications
    Replies: 7
    Last Post: 05-10-2010, 10:38 AM
  3. double click individual field in browse
    By Lance Gurd in forum Alpha Five Version 6
    Replies: 4
    Last Post: 08-24-2005, 05:25 AM
  4. Double row click
    By Jeff, Richards in forum Alpha Five Version 5
    Replies: 5
    Last Post: 05-28-2003, 04:58 PM
  5. Button Double Click
    By forskare in forum Alpha Five Version 4
    Replies: 1
    Last Post: 07-19-2001, 09:22 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •