First Loop - bugger, not working....

Questions, tips and tricks and techniques for scripting in Servoy

First Loop - bugger, not working....

Postby 4xjbh » Fri Feb 19, 2010 1:14 pm

I am attempting to add members to a group contact list, selected from a list, (check box is a calc "is selected")

I cannot get it to work. How do I get the contact_id of the current index? (???) How do I get this to only add the the contact ID for the checked record rather than all of the records in the foundset.

Code: Select all
for ( var i = 1 ; i <= forms.contact_dlg_lst.controller.getMaxRecordIndex() ; i++ )
{
   if (forms.contact_dlg_lst.isSelected = 1)
   {
      forms.group_layout_main.contact_group_to_contact_group_member.newRecord( )
      
      forms.group_layout_main.contact_group_to_contact_group_member.contact_id = ???   
   }


Thanks in advance.
Regards,

James
4xjbh
 
Posts: 146
Joined: Fri Feb 24, 2006 8:06 am
Location: Brisbane, Australia

Re: First Loop - bugger, not working....

Postby ROCLASI » Fri Feb 19, 2010 1:33 pm

Hi James,
You can fetch a record object from the foundset using foundset.getRecord(index).
Also I would use the getFoundSetCount() function to get the real amount of found records because the controller might nog have loaded all the records (does this in batches of 200 records).
So your code would look like this:

Code: Select all
var rc; // record object
var fsCount = databaseManager.getFoundSetCount(forms.contact_dlg_lst.foundset); // will get the count of all found records, not just the loaded ones.
for ( var i = 1 ; i <= fsCount ; i++ ) {
    rc = forms.contact_dlg_lst.foundset.getRecord(i);
    if (rc.isSelected = 1) {
        forms.group_layout_main.contact_group_to_contact_group_member.newRecord( )   
        forms.group_layout_main.contact_group_to_contact_group_member.contact_id = rc.theIdColumn;
    }
}



Hope this helps.
Robert Ivens
SAN Developer / Servoy Valued Professional / Servoy Certified Developer

ROCLASI Software Solutions / JBS Group, Partner
Mastodon: @roclasi
--
ServoyForge - Building Open Source Software.
PostgreSQL - The world's most advanced open source database.
User avatar
ROCLASI
Servoy Expert
 
Posts: 5438
Joined: Thu Oct 02, 2003 9:49 am
Location: Netherlands/Belgium

Re: First Loop - bugger, not working....

Postby 4xjbh » Sat Feb 20, 2010 2:41 am

This is adding all of the contacts in the foundset rather than the the selected ones.

I have confirmed "isSelected" is listed in the contact_dlg_lst dataproviders.

Code: Select all
   var rc; // record object
   var fsCount = databaseManager.getFoundSetCount(forms.contact_dlg_lst.foundset); // will get the count of all found records, not just the loaded ones.
   
   for ( var i = 1 ; i <= fsCount ; i++ ) {
    rc = forms.contact_dlg_lst.foundset.getRecord(i);
    if (rc.isSelected = 1) {
        forms.group_layout_main.contact_group_to_contact_group_member.newRecord( )   
        forms.group_layout_main.contact_group_to_contact_group_member.contact_id = rc.contact_id;
    }
}
Regards,

James
4xjbh
 
Posts: 146
Joined: Fri Feb 24, 2006 8:06 am
Location: Brisbane, Australia

Re: First Loop - bugger, not working....

Postby ptalbot » Sat Feb 20, 2010 2:47 am

Try
Code: Select all
if (rc.isSelected == 1) {

Otherwise you set the isSelected flag to 1.
Patrick Talbot
Freelance - Open Source - Servoy Valued Professional
https://www.servoyforge.net
Velocity rules! If you don't use it, you don't know what you're missing!
User avatar
ptalbot
 
Posts: 1659
Joined: Wed Mar 11, 2009 5:13 am
Location: Montreal, QC

Re: First Loop - bugger, not working....

Postby ROCLASI » Sat Feb 20, 2010 3:11 am

Heh, seems I've missed that. :oops:
Robert Ivens
SAN Developer / Servoy Valued Professional / Servoy Certified Developer

ROCLASI Software Solutions / JBS Group, Partner
Mastodon: @roclasi
--
ServoyForge - Building Open Source Software.
PostgreSQL - The world's most advanced open source database.
User avatar
ROCLASI
Servoy Expert
 
Posts: 5438
Joined: Thu Oct 02, 2003 9:49 am
Location: Netherlands/Belgium

Re: First Loop - bugger, not working....

Postby ptalbot » Sat Feb 20, 2010 3:32 am

ROCLASI wrote:Heh, seems I've missed that. :oops:

:) We all do, from time to time! :)
I think that Servoy in strict mode now checks for that and emit a warning.
Patrick Talbot
Freelance - Open Source - Servoy Valued Professional
https://www.servoyforge.net
Velocity rules! If you don't use it, you don't know what you're missing!
User avatar
ptalbot
 
Posts: 1659
Joined: Wed Mar 11, 2009 5:13 am
Location: Montreal, QC

Re: First Loop - bugger, not working....

Postby ROCLASI » Sat Feb 20, 2010 3:43 am

ptalbot wrote:
ROCLASI wrote:Heh, seems I've missed that. :oops:

:) We all do, from time to time! :)
I think that Servoy in strict mode now checks for that and emit a warning.


Yeah I have strict mode enabled and I like it.
Robert Ivens
SAN Developer / Servoy Valued Professional / Servoy Certified Developer

ROCLASI Software Solutions / JBS Group, Partner
Mastodon: @roclasi
--
ServoyForge - Building Open Source Software.
PostgreSQL - The world's most advanced open source database.
User avatar
ROCLASI
Servoy Expert
 
Posts: 5438
Joined: Thu Oct 02, 2003 9:49 am
Location: Netherlands/Belgium

Re: First Loop - bugger, not working....

Postby ptalbot » Sat Feb 20, 2010 4:18 am

ROCLASI wrote:
ptalbot wrote:
ROCLASI wrote:Heh, seems I've missed that. :oops:

:) We all do, from time to time! :)
I think that Servoy in strict mode now checks for that and emit a warning.


Yeah I have strict mode enabled and I like it.

They should also activate it on the forum, it would save us some embarassment sometimes... :D
Patrick Talbot
Freelance - Open Source - Servoy Valued Professional
https://www.servoyforge.net
Velocity rules! If you don't use it, you don't know what you're missing!
User avatar
ptalbot
 
Posts: 1659
Joined: Wed Mar 11, 2009 5:13 am
Location: Montreal, QC

Re: First Loop - bugger, not working....

Postby 4xjbh » Sat Feb 27, 2010 3:51 am

Thanks for the help
Regards,

James
4xjbh
 
Posts: 146
Joined: Fri Feb 24, 2006 8:06 am
Location: Brisbane, Australia


Return to Methods

Who is online

Users browsing this forum: No registered users and 6 guests