Home | Forums | Contact | Search | Syndication  
 
 [login] [create account]   Friday, June 20, 2025 
 
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!
 Architect Forums - SalesLogix Scripting & Customization
Forum to discuss writing script in Architect plugins for SalesLogix & general SalesLogix customization topics (for Windows client only). View the code of conduct for posting guidelines.
Forums RSS Feed


 Back to Forum List | Back to SalesLogix Scripting & Customization | New ThreadView:  Search:  
 Author  Thread: Trouble looping through datagrid values
muni1900
Posts: 21
 
Trouble looping through datagrid valuesYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 31 Oct 07 1:13 PM
I have a dynamic datagrid that I populate using vbscript. Initially, the grid will be empty. The datagrid is to be populated based on user selection. For example, user would click a button which brings up a lookup and selects a contact name --> That contact is to be added to the datagrid.

At my first try, I was able to get only one contact into grid because I set it up as datagrid.Recordset = objRS, where objRS contains only the user selected by the user. Duh - no wonder it kept replacing the previous contact info .

So in order to save whatever was already in the datagrid - I thought the following would work:

Set objRSOld = datagrid.Recordset

Set objRs = objSLXDB.GetNewRecordSet
With objRS
.Fields.Append "CONTACTID", adVarChar, 12
.Fields.Append "NAME", adVarChar, 32
.Open
End With

'Loop through values already in datagrid and add to the new object
If Not objRSOld Is Nothing Then

While Not objRSOld.eof

objRS.addnew
objRS.fields("CONTACTID").Value = objRSOld.fields("CONTACTID").value
objRS.fields("NAME").Value = objRSOld.fields("NAME").value

objRSOld.movenext

Wend

End If

'Finally add the new value that the user selected
objRS.addnew
objRS.fields("CONTACTID").Value = LookUp.ID
objRS.fields("NAME").Value = Lookup.DisplayName

datagrid.Recordset = objRS
datagrid.refresh

set objRS = nothing
Set objRSOld = nothing

My first try with this code - I was able to add a person then add another. The datagrid did successfully show both contact names. However, when I add a third contact, the first contact that added is replaced. Again if you add another person (the original 2nd contact is replaced). This keeps going with FIFO rule with 2 contacts.

I debugged and found that the while loop takes place only once - no other useful info came out of it. I have no idea why this is happening. Sorry about the essay question but anyone has any idea? Thanks.
[Reply][Quote]
muni1900
Posts: 21
 
Re: Trouble looping through datagrid valuesYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 31 Oct 07 2:19 PM
hi guys, I took a suggestion found on another site and tried this - it seems to be working. I replaced my loop with this loop. I am still trying to find out the differences. So I think there is no need to work on this. Thanks!

Dim i
While Not (objRSOld.eof)


objRSOld.movefirst
For i = 0 to objRSOld.recordcount - 1
objRS.addnew
objRS.fields("CONTACTID").Value = objRSOld.fields("CONTACTID").value
objRS.fields("NAME").Value = objRSOld.fields("NAME").value

objRSOld.movenext
Next
Wend

[Reply][Quote]
Jeff Weight
Posts: 219
 
Re: Trouble looping through datagrid valuesYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 01 Nov 07 9:38 AM
Muni,

I think I'll try and help you with this anyway, since I've done this sort of procedure a lot:

'First, dim the one recordset variable you will need to use
Dim objRSOld

'Set the recordset to the grid recordset
Set objRSOld = datagrid.Recordset

'Add a new record to the recordset
objRSOld.AddNew
objRSOld("CONTACTID") = LookUp.ID
objRSOld("NAME") = Lookup.DisplayName

'Set the datagrid back to the recordset
Set datagrid.Recordset = objRSOld

'All done!
Set objRSOld = Nothing
[Reply][Quote]
 Page 1 of 1 
  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!
 

 
 slxdeveloper.com is brought to you courtesy of Ryan Farley & Customer FX Corporation.
 This site, and all contents herein, are Copyright © 2025 Customer FX Corporation. The information and opinions expressed here are not endorsed by Sage Software.

code of conduct | Subscribe to the slxdeveloper.com Latest Article RSS feed
   
 
page cache (param): 6/20/2025 7:09:02 PM