Alpha Software Mobile Development Tools:   Alpha Anywhere    |   Alpha TransForm subscribe to our YouTube Channel  Follow Us on LinkedIn  Follow Us on Twitter  Follow Us on Facebook

Announcement

Collapse

The Alpha Software Forum Participation Guidelines

The Alpha Software Forum is a free forum created for Alpha Software Developer Community to ask for help, exchange ideas, and share solutions. Alpha Software strives to create an environment where all members of the community can feel safe to participate. In order to ensure the Alpha Software Forum is a place where all feel welcome, forum participants are expected to behave as follows:
  • Be professional in your conduct
  • Be kind to others
  • Be constructive when giving feedback
  • Be open to new ideas and suggestions
  • Stay on topic


Be sure all comments and threads you post are respectful. Posts that contain any of the following content will be considered a violation of your agreement as a member of the Alpha Software Forum Community and will be moderated:
  • Spam.
  • Vulgar language.
  • Quotes from private conversations without permission, including pricing and other sales related discussions.
  • Personal attacks, insults, or subtle put-downs.
  • Harassment, bullying, threatening, mocking, shaming, or deriding anyone.
  • Sexist, racist, homophobic, transphobic, ableist, or otherwise discriminatory jokes and language.
  • Sexually explicit or violent material, links, or language.
  • Pirated, hacked, or copyright-infringing material.
  • Encouraging of others to engage in the above behaviors.


If a thread or post is found to contain any of the content outlined above, a moderator may choose to take one of the following actions:
  • Remove the Post or Thread - the content is removed from the forum.
  • Place the User in Moderation - all posts and new threads must be approved by a moderator before they are posted.
  • Temporarily Ban the User - user is banned from forum for a period of time.
  • Permanently Ban the User - user is permanently banned from the forum.


Moderators may also rename posts and threads if they are too generic or do not property reflect the content.

Moderators may move threads if they have been posted in the incorrect forum.

Threads/Posts questioning specific moderator decisions or actions (such as "why was a user banned?") are not allowed and will be removed.

The owners of Alpha Software Corporation (Forum Owner) reserve the right to remove, edit, move, or close any thread for any reason; or ban any forum member without notice, reason, or explanation.

Community members are encouraged to click the "Report Post" icon in the lower left of a given post if they feel the post is in violation of the rules. This will alert the Moderators to take a look.

Alpha Software Corporation may amend the guidelines from time to time and may also vary the procedures it sets out where appropriate in a particular case. Your agreement to comply with the guidelines will be deemed agreement to any changes to it.



Bonus TIPS for Successful Posting

Try a Search First
It is highly recommended that a Search be done on your topic before posting, as many questions have been answered in prior posts. As with any search engine, the shorter the search term, the more "hits" will be returned, but the more specific the search term is, the greater the relevance of those "hits". Searching for "table" might well return every message on the board while "tablesum" would greatly restrict the number of messages returned.

When you do post
First, make sure you are posting your question in the correct forum. For example, if you post an issue regarding Desktop applications on the Mobile & Browser Applications board , not only will your question not be seen by the appropriate audience, it may also be removed or relocated.

The more detail you provide about your problem or question, the more likely someone is to understand your request and be able to help. A sample database with a minimum of records (and its support files, zipped together) will make it much easier to diagnose issues with your application. Screen shots of error messages are especially helpful.

When explaining how to reproduce your problem, please be as detailed as possible. Describe every step, click-by-click and keypress-by-keypress. Otherwise when others try to duplicate your problem, they may do something slightly different and end up with different results.

A note about attachments
You may only attach one file to each message. Attachment file size is limited to 2MB. If you need to include several files, you may do so by zipping them into a single archive.

If you forgot to attach your files to your post, please do NOT create a new thread. Instead, reply to your original message and attach the file there.

When attaching screen shots, it is best to attach an image file (.BMP, .JPG, .GIF, .PNG, etc.) or a zip file of several images, as opposed to a Word document containing the screen shots. Because Word documents are prone to viruses, many message board users will not open your Word file, therefore limiting their ability to help you.

Similarly, if you are uploading a zipped archive, you should simply create a .ZIP file and not a self-extracting .EXE as many users will not run your EXE file.
See more
See less

Set focus on repeating section row in Xbasic while looping through rows

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Set focus on repeating section row in Xbasic while looping through rows

    In my UX component for submitting lines of Accounts Payable bills, I do an ajax callback when user submits that loops through the repeating section rows and checks for job budget overages. If my code finds an overage on any row, I want to set a value into a field on the row that shows an alert on that row. HOWEVER, the value only seems to get set on the row that had focus before I click the Submit button. The e._set.OVER_BUDGET.value = "Yes" I use does not allow me to specify which row even though I am in the middle of a loop through the rows using [i] etc etc. My question is how to set focus on each row as I loop through them.

    Here is a verbal outline of my Xbasic code to loop through the records

    'get the number of records entered to use for looping through the entries and checking for overages
    dim n as n = e.dataSubmitted.JOB_CODE.size()
    for i = 1 to n
    jobCode = e.dataSubmitted.JOB_CODE[i]
    'execute my sql query using an argument for the jobCode variable (that was dimmed before the loop)
    'get a result from the query
    'if that result is xxxx , then set the value in the OVER_BUDGET field to Yes
    'HOW DO I SET THE FOCUS ON THE ROW I AM ON IN THE LOOP SO THAT I CAN SET THE VALUE?
    'I tried e._set.OVER_BUDGET[i].value = "Yes" but I don't think the e._set likes that because nothing happens unless it's the row I was on before
    'starting the loop
    next
    Carol King
    Developer of Custom Homebuilders' Solutions (CHS)
    http://www.CHSBuilderSoftware.com

    #2
    Re: Set focus on repeating section row in Xbasic while looping through rows

    P.S. It causes too many callbacks to use OnChange events in each row to do a call back and set the OVER_BUDGET alert to Yes if over budget. That's because there are several fields in the row that can change whether it is over budget or not. SO.... I am trying to loop through each row and set the value for OVER_BUDGET only when user clicks the Submit button. Then if I find any alerts, I give the user a confirm box message telling there are alerts and allowing them to cancel the submit in order to review them.
    Carol King
    Developer of Custom Homebuilders' Solutions (CHS)
    http://www.CHSBuilderSoftware.com

    Comment


      #3
      Re: Set focus on repeating section row in Xbasic while looping through rows

      Hey Carol,

      You want to return Javascript .setValue statements back to the client for those repeating section rows that need updating... and update them all at once.

      You know the RS row you're working with... so... build up a series of statements to return from your callback... something like...

      Code:
      "{dialog.object}.setValue('OVER_BUDGET:'" + i + ",'Yes');"
      Or... you're already in XBasic... update the SQL table with "Yes" and refresh the data on the client side.

      Comment


        #4
        Re: Set focus on repeating section row in Xbasic while looping through rows

        Thanks, David, I am trying that (in all my ignorance) and failing. Nothing happens if any records are over budget, no alerts are set and the wait message that is called before calling the function just stays on the screen.

        so before my loop I dim these variables: dim jsToReturn as c = "" dim overBudgetMarker = "No"

        then as I am looping through the repeating section of records, I am doing this after I do my sql query and get results:

        Code:
        if newPlusPostedCosts > budgetPlusCO then
        	overBudgetMarker = "Yes"									
        	jsToReturn = jsToReturn + "{dialog.object}.setValue('OVER_BUDGET:'" + i + ",'Yes');"
         else					
        	jsToReturn = jsToReturn + "{dialog.object}.setValue('OVER_BUDGET:'" + i + ",'No');"
        end if
        Then after I am out of the loop, the end of my function has this (I am hiding a wait message box that opened when user clicked Submit and calling a button that opens and advanced message box that lets user decide whether to continue or not, etc.:

        Code:
        if overBudgetMarker = "Yes" then
            jsToReturn = jsToReturn + "A5.msgBox.hide();"
            jsToReturn = jsToReturn + "{dialog.componentname}.V.R1.BUTTON_29').click();"
            GetOverBudgetAndPOsTotals = jsToReturn
        else
            jsToReturn = jsToReturn + "{grid.Object}.ajaxCallback('G',{Grid.RowNumber},'ConfirmPostTheEntries','','_getData=true');"	
            GetOverBudgetAndPOsTotals = jsToReturn
        
        end if
        Carol King
        Developer of Custom Homebuilders' Solutions (CHS)
        http://www.CHSBuilderSoftware.com

        Comment


          #5
          Re: Set focus on repeating section row in Xbasic while looping through rows

          Hey. I think you have a javascript error. I believe you need to move the closing single quote (') to the other side of the + i + part:

          Code:
          if newPlusPostedCosts > budgetPlusCO then
          	overBudgetMarker = "Yes"									
          	jsToReturn = jsToReturn + "{dialog.object}.setValue([COLOR="#008000"][B]'OVER_BUDGET:" + i + "'[/B][/COLOR],'Yes');"
           else					
          	jsToReturn = jsToReturn + "{dialog.object}.setValue([COLOR="#008000"][B]'OVER_BUDGET:" + i + "'[/B][/COLOR],'No');"
          end if
          It would explain why A5.msgBox.hide() never executes if you're adding it after these lines.

          Additionally, I think you're missing a $, left-paren, and quote here:

          Code:
          if overBudgetMarker = "Yes" then
              jsToReturn = jsToReturn + "A5.msgBox.hide();"
              jsToReturn = jsToReturn + "[B][COLOR="#008000"]$('{dialog.componentname}.V.R1.BUTTON_29')[/COLOR][/B].click();"
              GetOverBudgetAndPOsTotals = jsToReturn
          else
              jsToReturn = jsToReturn + "{grid.Object}.ajaxCallback('G',{Grid.RowNumber},'ConfirmPostTheEntries','','_getData=true');"	
              GetOverBudgetAndPOsTotals = jsToReturn
          
          end if
          ---
          Sarah
          Alpha Anywhere latest pre-release

          Comment


            #6
            Re: Set focus on repeating section row in Xbasic while looping through rows

            As well... you don't have to go after the DOM to click your button. You can use the {dialog.Object} method...

            Code:
            {dialog.object}.buttonClick(UXButtonId);

            Comment


              #7
              Re: Set focus on repeating section row in Xbasic while looping through rows

              Made these changes and now my button is being called successfully, but I'm back to where it is ONLY setting the value on the row that had focus before clicking the Submit button:

              Code:
              newPlusPostedCosts = newJobCostCodeTotal + costsJobAndCostCode
              				if newPlusPostedCosts > budgetPlusCO then
              					jsToReturn = jsToReturn + "{dialog.object}.setValue('OVER_BUDGET:" + i + "','Yes');"
              					overBudgetMarker = "Yes"
              				else
              					
              					jsToReturn = jsToReturn + "{dialog.object}.setValue('OVER_BUDGET:" + i + "','No');"
              				end if

              Code:
              if overBudgetMarker = "Yes" then
              	jsToReturn = jsToReturn + "A5.msgBox.hide();"
              	jsToReturn = jsToReturn + "$('{dialog.componentname}.V.R1.BUTTON_29').click();"
              	GetOverBudgetAndPOsTotals = jsToReturn
              	exit function
              else
              			jsToReturn = jsToReturn + "{grid.Object}.ajaxCallback('G',{Grid.RowNumber},'ConfirmPostTheEntries','','_getData=true');"	
              			GetOverBudgetAndPOsTotals = jsToReturn
              		end if
              Carol King
              Developer of Custom Homebuilders' Solutions (CHS)
              http://www.CHSBuilderSoftware.com

              Comment


                #8
                Re: Set focus on repeating section row in Xbasic while looping through rows

                Actually, let me amend the above. I don't think it is the row that has focus before clicking the submit button. I think it is only setting the values on the last row.
                Carol King
                Developer of Custom Homebuilders' Solutions (CHS)
                http://www.CHSBuilderSoftware.com

                Comment


                  #9
                  Re: Set focus on repeating section row in Xbasic while looping through rows

                  What is your entire routine?
                  Alpha Anywhere latest pre-release

                  Comment


                    #10
                    Re: Set focus on repeating section row in Xbasic while looping through rows

                    Ok, you asked for it, Sarah. (thank you) There is actually a lot more to the function than I was posting here with trying to set 2 other alerts, etc., but I didn't want to overload this thread with all that...

                    Code:
                    function GetOverBudgetAndPOsTotals as c (e as p)
                    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''	
                    'open connection
                    dim cn as sql::connection
                    dim cs as c 
                    
                    cs = my particular connection
                    
                    dim flag as l 
                    flag = cn.open(cs)
                    if flag = .f. then 
                    	dim msg as c 
                    	msg = "Could not connect to database. Error reported was: " + cn.CallResult.text
                    	msg = js_escape(msg)
                    	dim jscmd as c = ""
                    	jscmd = "A5.msgBox.hide();"  
                    	jscmd = jscmd + "alert('" + msg + "');"
                    	GetOverBudgetAndPOsTotals = jscmd
                    	exit function 
                    end if
                    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
                    dim vendorCode
                    vendorCode = e.dataSubmitted.AP_VENDOR_CODE
                    
                    dim overBudgetMarker as c
                    overBudgetMarker = "No"
                    
                    dim overPOsMarker as c
                    overPOsMarker = "No"
                    
                    dim changeOrdersMarker as c
                    changeOrdersMarker = "No"
                    
                    dim jsToReturn as c
                    jsToReturn = ""
                    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
                    'get the number of records entered to use for looping through the entries and checking for overages
                    dim n as n = e.dataSubmitted.GL_DOCUMENT.size()
                    for i = 1 to n
                    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
                    	dim jobCode
                    	jobCode = e.dataSubmitted.JOB_CODE[i]
                    		
                    	dim costCode as n
                    	costCode = convert_type(e.dataSubmitted.SUB_CODE[i],"N")
                    		
                    	if convert_type(e.dataSubmitted.Total[i],"N") <> 0 then
                    		if jobCode <> "H" then
                    			if e.dataSubmitted.JOB_IN_HISTORICAL_ALERT[i] = "No" then
                    								
                    				'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
                    				'First, Loop through records in repeating section and get total of new entries for the same job and vendor
                    				'This will give us the newVendorJobTotal				
                    				dim newVendorJobTotal as n
                    				newVendorJobTotal = 0
                    				
                    				for i = 1 to n
                    					if convert_type(e.dataSubmitted.Total[i],"N") <> 0 then						
                    						if e.dataSubmitted.JOB_CODE[i] = jobCode then
                    							newVendorJobTotal = newVendorJobTotal + convert_type(e.dataSubmitted.Total[i],"N")
                    						end if
                    					end if
                    				next
                    				'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
                    				'Loop through records in repeating section and get total of new entries for the same job and cost code
                    				dim newJobCostCodeTotal as n
                    				newJobCostCodeTotal = 0
                    				
                    				for i = 1 to n
                    					if convert_type(e.dataSubmitted.Total[i],"N") <> 0 then
                    						
                    						if e.dataSubmitted.JOB_CODE[i] = jobCode then
                    							if convert_type(e.dataSubmitted.SUB_CODE[i],"N") = costCode then
                    								newJobCostCodeTotal = newJobCostCodeTotal + convert_type(e.dataSubmitted.Total[i],"N")
                    							end if
                    						end if
                    					end if
                    				next
                    				''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
                    				'check to see if there is a budget line marked as Show Yes for the job and cost code on the current row in the repeating section
                    				sql40 = "select count(*) from QryJobsBudgetTotalsShowYes where JOB_CODE = :whatJob and SUB_CODE = :whatCostCode"
                    				dim args40 as sql::Arguments
                    				args40.add("whatJob",jobCode)
                    				args40.add("whatCostCode",costCode)
                    				cn.execute(sql40,args40)
                    				dim rs40 as sql::ResultSet
                    				rs40 = cn.ResultSet
                    				
                    				dim countBudgetLine as n
                    				countBudgetLine = convert_type(rs40.data(1),"N")
                    				
                    				dim budgetAmount as n
                    				budgetAmount = 0
                    				
                    				if countBudgetLine > 0 then
                    					sql41 = "select Total from QryJobsBudgetTotalsShowYes where JOB_CODE = :whatJob and SUB_CODE = :whatCostCode"
                    					dim args41 as sql::Arguments
                    					args41.add("whatJob",jobCode)
                    					args41.add("whatCostCode",costCode)
                    					cn.execute(sql41,args41)
                    					dim rs41 as sql::ResultSet
                    					rs41 = cn.ResultSet
                    					
                    					budgetAmount = convert_type(rs41.data(1),"N")
                    				 
                    				end if
                    				
                    				''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
                    				'check whether there are approved Change Orders and get the total cost of those for the job and cost code
                    				sql45 = "select count(*) from QryCOTotals where JOB_CODE = :whatJob and SUB_CODE = :whatCostCode and Approval = 1"
                    				dim args45 as sql::Arguments
                    				args45.add("whatJob",jobCode)
                    				args45.add("whatCostCode",costCode)
                    				cn.execute(sql45,args45)
                    				dim rs45 as sql::ResultSet
                    				rs45 = cn.ResultSet
                    				
                    				dim countCOLines as n
                    				countCOLines = convert_type(rs45.data(1),"N")
                    				
                    				dim coAmount as n
                    				coAmount = 0
                    				
                    				if countCOLines > 0 then
                    					sql46 = "select Sum(TTL_COST)from QryCOTotals where JOB_CODE = :whatJob and SUB_CODE = :whatCostCode and Approval = 1"
                    					dim args46 as sql::Arguments
                    					args46.add("whatJob",jobCode)
                    					args46.add("whatCostCode",costCode)
                    					cn.execute(sql46,args46)
                    					dim rs46 as sql::ResultSet
                    					rs46 = cn.ResultSet
                    					
                    					coAmount = convert_type(rs46.data(1),"N")
                    				end if
                    				
                    				'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
                    				'add budgetAmount and coAmount together to get the total of budgeted and CO estimated costs
                    				
                    				dim budgetPlusCO as n
                    				budgetPlusCO = budgetAmount + coAmount
                    				
                    				''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
                    				'get the actual job costs posted for the job and cost code
                    				sql50 = "select count(*) from QryJobsActualJobCostTotalsNoJoins where JOB_CODE = :whatJob and JOB_SUB_CODE = :whatCostCode"
                    				dim args50 as sql::Arguments
                    				args50.add("whatJob",jobCode)
                    				args50.add("whatCostCode",costCode)
                    				cn.execute(sql50,args50)
                    				dim rs50 as sql::ResultSet
                    				rs50 = cn.ResultSet
                    				
                    				dim countActualCostLines as n
                    				countActualCostLines = convert_type(rs50.data(1),"N")
                    				
                    				dim costsJobAndCostCode as n
                    				costsJobAndCostCode = 0
                    				
                    				if countActualCostLines > 0 then
                    					sql51 = "select Sum(TOTAL)from QryJobsActualJobCostTotalsNoJoins where JOB_CODE = :whatJob and JOB_SUB_CODE = :whatCostCode"
                    					dim args51 as sql::Arguments
                    					args51.add("whatJob",jobCode)
                    					args51.add("whatCostCode",costCode)
                    					cn.execute(sql51,args51)
                    					dim rs51 as sql::ResultSet
                    					rs51 = cn.ResultSet
                    					
                    					costsJobAndCostCode = convert_type(rs51.data(1),"N")
                    				end if
                    				'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
                    				'check if new costs plus posted costs are over budget for job and cost code
                    				dim newPlusPostedCosts as n
                    				newPlusPostedCosts = newJobCostCodeTotal + costsJobAndCostCode
                    				if newPlusPostedCosts > budgetPlusCO then
                    					jsToReturn = jsToReturn + "{dialog.object}.setValue('OVER_BUDGET:" + i + "','Yes');"
                    					overBudgetMarker = "Yes"
                    				else
                    					
                    					jsToReturn = jsToReturn + "{dialog.object}.setValue('OVER_BUDGET:" + i + "','No');"
                    				end if		
                    					
                    				'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
                    				'NOW need to check if over POs for vendor and job
                    				sql60 = "select count(*) from QryPOTotalsNoJoins where JOB_CODE = :whatJob and AP_VENDOR_CODE = :whatVendor"
                    				dim args60 as sql::Arguments
                    				args60.add("whatJob",jobCode)
                    				args60.add("whatVendor",vendorCode)
                    				cn.execute(sql60,args60)
                    				dim rs60 as sql::ResultSet
                    				rs60 = cn.ResultSet
                    				
                    				dim countPOsForJobVendor as n
                    				countPOsForJobVendor = convert_type(rs60.data(1),"N")
                    				
                    				dim posForJobAndVendor as n
                    				posForJobAndVendor = 0
                    				
                    				if countPOsForJobVendor > 0 then
                    					sql61 = "select Sum(PO_B4TAX)from QryPOTotalsNoJoins where JOB_CODE = :whatJob and AP_VENDOR_CODE = :whatVendor"
                    					dim args61 as sql::Arguments
                    					args61.add("whatJob",jobCode)
                    					args61.add("whatVendor",vendorCode)
                    					cn.execute(sql61,args61)
                    					dim rs61 as sql::ResultSet
                    					rs61 = cn.ResultSet
                    					
                    					posForJobAndVendor = convert_type(rs61.data(1),"N") 
                    				end if
                    				
                    				'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
                    				'get total of actual posted costs for job and vendor
                    				sql70 = "select count(*) from QryJobsActualJobCostTotalsNoJoins where JOB_CODE = :whatJob and AP_VENDOR_CODE = :whatVendor"
                    				dim args70 as sql::Arguments
                    				args70.add("whatJob",jobCode)
                    				args70.add("whatVendor",vendorCode)
                    				cn.execute(sql70,args70)
                    				dim rs70 as sql::ResultSet
                    				rs70 = cn.ResultSet
                    				
                    				dim countActualCostsJobVendor as n
                    				countActualCostsJobVendor = convert_type(rs70.data(1),"N")
                    				
                    				dim costsJobAndVendor as n
                    				costsJobAndVendor = 0
                    				
                    				if countActualCostsJobVendor > 0 then
                    					sql71 = "select Sum(TOTAL)from QryJobsActualJobCostTotalsNoJoins where JOB_CODE = :whatJob and AP_VENDOR_CODE = :whatVendor"
                    					dim args71 as sql::Arguments
                    					args71.add("whatJob",jobCode)
                    					args71.add("whatVendor",vendorCode)
                    					cn.execute(sql71,args71)
                    					dim rs71 as sql::ResultSet
                    					rs71 = cn.ResultSet
                    					
                    					costsJobAndVendor = convert_type(rs71.data(1),"N")
                    				end if
                    				'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
                    				'get total of new costs plus posted costs for job and vendor
                    				dim newPlusPostedCostsForVendorJob as n
                    				newPlusPostedCostsForVendorJob = newVendorJobTotal + costsJobAndVendor
                    				'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
                    				'compare new plus posted costs for job and vendor to po's issued for the job and vendor
                    				
                    				if newPlusPostedCostsForVendorJob > posForJobAndVendor then
                    					jsToReturn = jsToReturn + "{dialog.object}.setValue('OVER_POS:" + i + "','Yes');"
                    					overPOsMarker = "Yes"
                    				else
                    					'e._set.OVER_POS.value = "No"
                    					jsToReturn = jsToReturn + "{dialog.object}.setValue('OVER_POS:" + i + "','No');"	
                    				end if
                    				'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
                    				'ALSO, check to see if there are any Change Orders for the job and cost code selected.
                    				'If there are, set the CO_ALERT field to Yes so that the exclamation icon will show next to the Markup field.
                    				sql80 = "select count(*) from TblChangeOrdersData where JOB_CODE = :whatJob and SUB_CODE = :whatCostCode and CO_APPROVED <> 0"
                    				dim args80 as sql::Arguments
                    				args80.add("whatJob",jobCode)
                    				args80.add("whatCostCode",costCode)
                    				cn.execute(sql80,args80)
                    				dim rs80 as sql::ResultSet
                    				rs80 = cn.ResultSet
                    				
                    				dim countCOs as n
                    				countCOs = convert_type(rs80.data(1),"N")
                    				
                    				if countCOs > 0 then
                    					
                    					jsToReturn = jsToReturn + "{dialog.object}.setValue('COS_ALERT:" + i + "','Yes');"
                    					changeOrdersMarker = "Yes"	
                    				else
                    					'e._set.COS_ALERT.value = "No"
                    					jsToReturn = jsToReturn + "{dialog.object}.setValue('COS_ALERT:" + i + "','No');"
                    				end if
                    			''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
                    				
                    			end if 'checking if job is in historical
                    		end if 'check if job greater than H	
                    	end if 'check if amount not zero
                    next
                    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
                    cn.Close()
                    
                    if overBudgetMarker = "Yes" then
                    	jsToReturn = jsToReturn + "A5.msgBox.hide();"
                    	jsToReturn = jsToReturn + "$('{dialog.componentname}.V.R1.BUTTON_29').click();"
                    	GetOverBudgetAndPOsTotals = jsToReturn
                    	exit function
                    else
                    	if overPOsMarker = "Yes" then
                    		jsToReturn = jsToReturn + "A5.msgBox.hide();"
                    		jsToReturn = jsToReturn + "$('{dialog.componentname}.V.R1.BUTTON_29').click();"
                    		GetOverBudgetAndPOsTotals = jsToReturn
                    		exit function
                    	else
                    		if changeOrdersMarker = "Yes" then
                    			jsToReturn = jsToReturn + "A5.msgBox.hide();"
                    			jsToReturn = jsToReturn + "$('{dialog.componentname}.V.R1.BUTTON_29').click();"
                    			GetOverBudgetAndPOsTotals = jsToReturn
                    			exit function	
                    		else
                    			jsToReturn = jsToReturn + "{grid.Object}.ajaxCallback('G',{Grid.RowNumber},'ConfirmPostTheEntries','','_getData=true');"	
                    			GetOverBudgetAndPOsTotals = jsToReturn
                    		end if
                    	end if	
                    end if
                    	
                    end function
                    Carol King
                    Developer of Custom Homebuilders' Solutions (CHS)
                    http://www.CHSBuilderSoftware.com

                    Comment


                      #11
                      Re: Set focus on repeating section row in Xbasic while looping through rows

                      Here's a quick video with the setValue stuff being built in a test case... seems to work ok...

                      http://www.youtube.com/watch?v=FZX0uhbFbJs

                      Comment


                        #12
                        Re: Set focus on repeating section row in Xbasic while looping through rows

                        Don't you have to reference each a5w_instance for each row of the repeating section? I've had to do that in the past I thought.

                        Comment


                          #13
                          Re: Set focus on repeating section row in Xbasic while looping through rows

                          David,

                          Would you be willing to upload the component you used to loop through the repeating section?

                          Comment


                            #14
                            Re: Set focus on repeating section row in Xbasic while looping through rows

                            Originally posted by kingcarol View Post
                            Ok, you asked for it, Sarah. (thank you) There is actually a lot more to the function than I was posting here with trying to set 2 other alerts, etc., but I didn't want to overload this thread with all that...

                            Code:
                            function GetOverBudgetAndPOsTotals as c (e as p)
                            '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''	
                            'open connection
                            dim cn as sql::connection
                            dim cs as c 
                            
                            cs = my particular connection
                            
                            dim flag as l 
                            flag = cn.open(cs)
                            if flag = .f. then 
                            	dim msg as c 
                            	msg = "Could not connect to database. Error reported was: " + cn.CallResult.text
                            	msg = js_escape(msg)
                            	dim jscmd as c = ""
                            	jscmd = "A5.msgBox.hide();"  
                            	jscmd = jscmd + "alert('" + msg + "');"
                            	GetOverBudgetAndPOsTotals = jscmd
                            	exit function 
                            end if
                            ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
                            dim vendorCode
                            vendorCode = e.dataSubmitted.AP_VENDOR_CODE
                            
                            dim overBudgetMarker as c
                            overBudgetMarker = "No"
                            
                            dim overPOsMarker as c
                            overPOsMarker = "No"
                            
                            dim changeOrdersMarker as c
                            changeOrdersMarker = "No"
                            
                            dim jsToReturn as c
                            jsToReturn = ""
                            ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
                            'get the number of records entered to use for looping through the entries and checking for overages
                            dim n as n = e.dataSubmitted.GL_DOCUMENT.size()
                            for i = 1 to n
                            ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
                            	dim jobCode
                            	jobCode = e.dataSubmitted.JOB_CODE[i]
                            		
                            	dim costCode as n
                            	costCode = convert_type(e.dataSubmitted.SUB_CODE[i],"N")
                            		
                            	if convert_type(e.dataSubmitted.Total[i],"N") <> 0 then
                            		if jobCode <> "H" then
                            			if e.dataSubmitted.JOB_IN_HISTORICAL_ALERT[i] = "No" then
                            								
                            				'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
                            				'First, Loop through records in repeating section and get total of new entries for the same job and vendor
                            				'This will give us the newVendorJobTotal				
                            				dim newVendorJobTotal as n
                            				newVendorJobTotal = 0
                            				
                            				for i = 1 to n
                            					if convert_type(e.dataSubmitted.Total[i],"N") <> 0 then						
                            						if e.dataSubmitted.JOB_CODE[i] = jobCode then
                            							newVendorJobTotal = newVendorJobTotal + convert_type(e.dataSubmitted.Total[i],"N")
                            						end if
                            					end if
                            				next
                            				'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
                            				'Loop through records in repeating section and get total of new entries for the same job and cost code
                            				dim newJobCostCodeTotal as n
                            				newJobCostCodeTotal = 0
                            				
                            				for i = 1 to n
                            					if convert_type(e.dataSubmitted.Total[i],"N") <> 0 then
                            						
                            						if e.dataSubmitted.JOB_CODE[i] = jobCode then
                            							if convert_type(e.dataSubmitted.SUB_CODE[i],"N") = costCode then
                            								newJobCostCodeTotal = newJobCostCodeTotal + convert_type(e.dataSubmitted.Total[i],"N")
                            							end if
                            						end if
                            					end if
                            				next
                            				''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
                            				'check to see if there is a budget line marked as Show Yes for the job and cost code on the current row in the repeating section
                            				sql40 = "select count(*) from QryJobsBudgetTotalsShowYes where JOB_CODE = :whatJob and SUB_CODE = :whatCostCode"
                            				dim args40 as sql::Arguments
                            				args40.add("whatJob",jobCode)
                            				args40.add("whatCostCode",costCode)
                            				cn.execute(sql40,args40)
                            				dim rs40 as sql::ResultSet
                            				rs40 = cn.ResultSet
                            				
                            				dim countBudgetLine as n
                            				countBudgetLine = convert_type(rs40.data(1),"N")
                            				
                            				dim budgetAmount as n
                            				budgetAmount = 0
                            				
                            				if countBudgetLine > 0 then
                            					sql41 = "select Total from QryJobsBudgetTotalsShowYes where JOB_CODE = :whatJob and SUB_CODE = :whatCostCode"
                            					dim args41 as sql::Arguments
                            					args41.add("whatJob",jobCode)
                            					args41.add("whatCostCode",costCode)
                            					cn.execute(sql41,args41)
                            					dim rs41 as sql::ResultSet
                            					rs41 = cn.ResultSet
                            					
                            					budgetAmount = convert_type(rs41.data(1),"N")
                            				 
                            				end if
                            				
                            				''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
                            				'check whether there are approved Change Orders and get the total cost of those for the job and cost code
                            				sql45 = "select count(*) from QryCOTotals where JOB_CODE = :whatJob and SUB_CODE = :whatCostCode and Approval = 1"
                            				dim args45 as sql::Arguments
                            				args45.add("whatJob",jobCode)
                            				args45.add("whatCostCode",costCode)
                            				cn.execute(sql45,args45)
                            				dim rs45 as sql::ResultSet
                            				rs45 = cn.ResultSet
                            				
                            				dim countCOLines as n
                            				countCOLines = convert_type(rs45.data(1),"N")
                            				
                            				dim coAmount as n
                            				coAmount = 0
                            				
                            				if countCOLines > 0 then
                            					sql46 = "select Sum(TTL_COST)from QryCOTotals where JOB_CODE = :whatJob and SUB_CODE = :whatCostCode and Approval = 1"
                            					dim args46 as sql::Arguments
                            					args46.add("whatJob",jobCode)
                            					args46.add("whatCostCode",costCode)
                            					cn.execute(sql46,args46)
                            					dim rs46 as sql::ResultSet
                            					rs46 = cn.ResultSet
                            					
                            					coAmount = convert_type(rs46.data(1),"N")
                            				end if
                            				
                            				'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
                            				'add budgetAmount and coAmount together to get the total of budgeted and CO estimated costs
                            				
                            				dim budgetPlusCO as n
                            				budgetPlusCO = budgetAmount + coAmount
                            				
                            				''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
                            				'get the actual job costs posted for the job and cost code
                            				sql50 = "select count(*) from QryJobsActualJobCostTotalsNoJoins where JOB_CODE = :whatJob and JOB_SUB_CODE = :whatCostCode"
                            				dim args50 as sql::Arguments
                            				args50.add("whatJob",jobCode)
                            				args50.add("whatCostCode",costCode)
                            				cn.execute(sql50,args50)
                            				dim rs50 as sql::ResultSet
                            				rs50 = cn.ResultSet
                            				
                            				dim countActualCostLines as n
                            				countActualCostLines = convert_type(rs50.data(1),"N")
                            				
                            				dim costsJobAndCostCode as n
                            				costsJobAndCostCode = 0
                            				
                            				if countActualCostLines > 0 then
                            					sql51 = "select Sum(TOTAL)from QryJobsActualJobCostTotalsNoJoins where JOB_CODE = :whatJob and JOB_SUB_CODE = :whatCostCode"
                            					dim args51 as sql::Arguments
                            					args51.add("whatJob",jobCode)
                            					args51.add("whatCostCode",costCode)
                            					cn.execute(sql51,args51)
                            					dim rs51 as sql::ResultSet
                            					rs51 = cn.ResultSet
                            					
                            					costsJobAndCostCode = convert_type(rs51.data(1),"N")
                            				end if
                            				'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
                            				'check if new costs plus posted costs are over budget for job and cost code
                            				dim newPlusPostedCosts as n
                            				newPlusPostedCosts = newJobCostCodeTotal + costsJobAndCostCode
                            				if newPlusPostedCosts > budgetPlusCO then
                            					jsToReturn = jsToReturn + "{dialog.object}.setValue('OVER_BUDGET:" + i + "','Yes');"
                            					overBudgetMarker = "Yes"
                            				else
                            					
                            					jsToReturn = jsToReturn + "{dialog.object}.setValue('OVER_BUDGET:" + i + "','No');"
                            				end if		
                            					
                            				'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
                            				'NOW need to check if over POs for vendor and job
                            				sql60 = "select count(*) from QryPOTotalsNoJoins where JOB_CODE = :whatJob and AP_VENDOR_CODE = :whatVendor"
                            				dim args60 as sql::Arguments
                            				args60.add("whatJob",jobCode)
                            				args60.add("whatVendor",vendorCode)
                            				cn.execute(sql60,args60)
                            				dim rs60 as sql::ResultSet
                            				rs60 = cn.ResultSet
                            				
                            				dim countPOsForJobVendor as n
                            				countPOsForJobVendor = convert_type(rs60.data(1),"N")
                            				
                            				dim posForJobAndVendor as n
                            				posForJobAndVendor = 0
                            				
                            				if countPOsForJobVendor > 0 then
                            					sql61 = "select Sum(PO_B4TAX)from QryPOTotalsNoJoins where JOB_CODE = :whatJob and AP_VENDOR_CODE = :whatVendor"
                            					dim args61 as sql::Arguments
                            					args61.add("whatJob",jobCode)
                            					args61.add("whatVendor",vendorCode)
                            					cn.execute(sql61,args61)
                            					dim rs61 as sql::ResultSet
                            					rs61 = cn.ResultSet
                            					
                            					posForJobAndVendor = convert_type(rs61.data(1),"N") 
                            				end if
                            				
                            				'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
                            				'get total of actual posted costs for job and vendor
                            				sql70 = "select count(*) from QryJobsActualJobCostTotalsNoJoins where JOB_CODE = :whatJob and AP_VENDOR_CODE = :whatVendor"
                            				dim args70 as sql::Arguments
                            				args70.add("whatJob",jobCode)
                            				args70.add("whatVendor",vendorCode)
                            				cn.execute(sql70,args70)
                            				dim rs70 as sql::ResultSet
                            				rs70 = cn.ResultSet
                            				
                            				dim countActualCostsJobVendor as n
                            				countActualCostsJobVendor = convert_type(rs70.data(1),"N")
                            				
                            				dim costsJobAndVendor as n
                            				costsJobAndVendor = 0
                            				
                            				if countActualCostsJobVendor > 0 then
                            					sql71 = "select Sum(TOTAL)from QryJobsActualJobCostTotalsNoJoins where JOB_CODE = :whatJob and AP_VENDOR_CODE = :whatVendor"
                            					dim args71 as sql::Arguments
                            					args71.add("whatJob",jobCode)
                            					args71.add("whatVendor",vendorCode)
                            					cn.execute(sql71,args71)
                            					dim rs71 as sql::ResultSet
                            					rs71 = cn.ResultSet
                            					
                            					costsJobAndVendor = convert_type(rs71.data(1),"N")
                            				end if
                            				'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
                            				'get total of new costs plus posted costs for job and vendor
                            				dim newPlusPostedCostsForVendorJob as n
                            				newPlusPostedCostsForVendorJob = newVendorJobTotal + costsJobAndVendor
                            				'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
                            				'compare new plus posted costs for job and vendor to po's issued for the job and vendor
                            				
                            				if newPlusPostedCostsForVendorJob > posForJobAndVendor then
                            					jsToReturn = jsToReturn + "{dialog.object}.setValue('OVER_POS:" + i + "','Yes');"
                            					overPOsMarker = "Yes"
                            				else
                            					'e._set.OVER_POS.value = "No"
                            					jsToReturn = jsToReturn + "{dialog.object}.setValue('OVER_POS:" + i + "','No');"	
                            				end if
                            				'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
                            				'ALSO, check to see if there are any Change Orders for the job and cost code selected.
                            				'If there are, set the CO_ALERT field to Yes so that the exclamation icon will show next to the Markup field.
                            				sql80 = "select count(*) from TblChangeOrdersData where JOB_CODE = :whatJob and SUB_CODE = :whatCostCode and CO_APPROVED <> 0"
                            				dim args80 as sql::Arguments
                            				args80.add("whatJob",jobCode)
                            				args80.add("whatCostCode",costCode)
                            				cn.execute(sql80,args80)
                            				dim rs80 as sql::ResultSet
                            				rs80 = cn.ResultSet
                            				
                            				dim countCOs as n
                            				countCOs = convert_type(rs80.data(1),"N")
                            				
                            				if countCOs > 0 then
                            					
                            					jsToReturn = jsToReturn + "{dialog.object}.setValue('COS_ALERT:" + i + "','Yes');"
                            					changeOrdersMarker = "Yes"	
                            				else
                            					'e._set.COS_ALERT.value = "No"
                            					jsToReturn = jsToReturn + "{dialog.object}.setValue('COS_ALERT:" + i + "','No');"
                            				end if
                            			''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
                            				
                            			end if 'checking if job is in historical
                            		end if 'check if job greater than H	
                            	end if 'check if amount not zero
                            next
                            '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
                            cn.Close()
                            
                            if overBudgetMarker = "Yes" then
                            	jsToReturn = jsToReturn + "A5.msgBox.hide();"
                            	jsToReturn = jsToReturn + "$('{dialog.componentname}.V.R1.BUTTON_29').click();"
                            	GetOverBudgetAndPOsTotals = jsToReturn
                            	exit function
                            else
                            	if overPOsMarker = "Yes" then
                            		jsToReturn = jsToReturn + "A5.msgBox.hide();"
                            		jsToReturn = jsToReturn + "$('{dialog.componentname}.V.R1.BUTTON_29').click();"
                            		GetOverBudgetAndPOsTotals = jsToReturn
                            		exit function
                            	else
                            		if changeOrdersMarker = "Yes" then
                            			jsToReturn = jsToReturn + "A5.msgBox.hide();"
                            			jsToReturn = jsToReturn + "$('{dialog.componentname}.V.R1.BUTTON_29').click();"
                            			GetOverBudgetAndPOsTotals = jsToReturn
                            			exit function	
                            		else
                            			jsToReturn = jsToReturn + "{grid.Object}.ajaxCallback('G',{Grid.RowNumber},'ConfirmPostTheEntries','','_getData=true');"	
                            			GetOverBudgetAndPOsTotals = jsToReturn
                            		end if
                            	end if	
                            end if
                            	
                            end function
                            Well, I'm confident it's not your JS, so it had to be something in your loop. Which, it appears that it is something else in your loop:

                            Your 2 inner for loops are referencing i, the same variable you use for the outer loop. You iterate to n. n is the # of rows in your repeating section. When you're js code is output, i = n. So. Only the last row is updated. When the outer loop increments i, it will exceed n. Or maybe equal n? At any rate, your loop only goes once. So you only get one set of code. And it's always gonna be the last record.

                            Maybe rename your inner loop variables to j or k?

                            Good luck
                            ---
                            Sarah
                            Alpha Anywhere latest pre-release

                            Comment


                              #15
                              Re: Set focus on repeating section row in Xbasic while looping through rows

                              Yay, Yay, Yay! That was it, Sarah... totally makes sense. THANK YOU ALL! I LOVE THIS FORUM.
                              I will now show off my working stuff in a video because I'm so happy about it I can't help myself.
                              http://screencast.com/t/ZDU7nyO4
                              Carol King
                              Developer of Custom Homebuilders' Solutions (CHS)
                              http://www.CHSBuilderSoftware.com

                              Comment

                              Working...
                              X