Adding or removing records from the end of my series

I have a series of child records which belong to a particular artwork. These are editions of that artwork (posters for eg). I have some code to create a set number of child ‘edition’ records. This works.

I would now like to be able to add to and reduce the number of editions, but whichever way I address my maxRecordIndex, I get only 200 records being added or removed, its all turning into a mess. The original code to make these child records is:

if (other_criteria_to_editions.getSize()>0)
{
forms.edition_list.controller.showRecords(other_criteria_to_editions)
}
else
{
var vthePressedButton = plugins.dialogs.showInfoDialog(‘Editions’,'This button will make a related group of editions\nfor ’ + reference_number + ‘. Are you sure you want to continue?’ , ‘OK’, ‘Cancel’)
if (vthePressedButton == ‘Cancel’)
{
return
}
if (vthePressedButton == ‘OK’)
{
var veditionSize = plugins.dialogs.showInputDialog(‘How many editions?’,‘How big is this set of editions?’)
for ( var i = 1 ; i <= veditionSize ; i++ )
{
other_criteria_to_editions.newRecord(false,true)
other_criteria_to_editions.edition_number = i
other_criteria_to_editions.of_maximum = veditionSize
other_criteria_to_editions.title = title
other_criteria_to_editions.edition_text_id = i + ‘/’ + veditionSize

}
forms.edition_list.controller.showRecords(other_criteria_to_editions)
}
}

The code to add to the set is :

var thePressedButton = plugins.dialogs.showWarningDialog(‘Warning’, ‘You are about to increase the edition size,\nare you sure?’,‘OK’, ‘Cancel’);
if (thePressedButton == ‘Cancel’)
{
}
if (thePressedButton == ‘OK’)
{
controller.setSelectedIndex(1)
var voc_reference = reference_number
for(var i=1;i<=foundset.getSize();i++)
{
foundset.setSelectedIndex(i)
if (reference_number != voc_reference)
{
var thePressedButton = plugins.dialogs.showErrorDialog(‘Error’, ‘You have a mixed group of editions…\nYou cannot increase the edition size\nunless you have chosen just ONE OC Reference’,‘OK’);
return
}
}
controller.setSelectedIndex(1)

var vmaxrecordindex = controller.getMaxRecordIndex() +1
var veditionSize = plugins.dialogs.showInputDialog(‘How many?’,‘How many would you like to add?’)
var vtotalsize = vmaxrecordindex + veditionSize
for ( var i = 0 ; i <= veditionSize -1 ; i++ )
{
controller.newRecord(false,true)
reference_number = voc_reference
forms.edition_list.edition_number = vmaxrecordindex ++
title = editions_to_other_criteria.title
}
controller.find()
reference_number = voc_reference
controller.search()

controller.setSelectedIndex(controller.getMaxRecordIndex())
var newMaxRecordIndex = controller.getMaxRecordIndex()
controller.setSelectedIndex(1)
// var vnewtotalsize = controller.getMaxRecordIndex()
// var vnewtotalsize = foundset.getSize()
controller.setSelectedIndex(1)
for ( var i = 0 ; i <= vtotalsize ; i++ )
{
foundset.setSelectedIndex(i)
of_maximum = newMaxRecordIndex
}

}

Any pointers on how to get this working, or perhaps do it a little more elegantly, would be gratefully received (also how to reverse the process and REDUCE a number of child records)

Thanks

Bevil[/quote]

Thunder:
controller.setSelectedIndex(controller.getMaxRecordIndex())
var newMaxRecordIndex = controller.getMaxRecordIndex()
controller.setSelectedIndex(1)
// var vnewtotalsize = controller.getMaxRecordIndex()
// var vnewtotalsize = foundset.getSize()
controller.setSelectedIndex(1)
for ( var i = 0 ; i <= vtotalsize ; i++ )
{
foundset.setSelectedIndex(i)
of_maximum = newMaxRecordIndex
}

}

replace this with

of_maximum = DatabaseManager.getFoundSetCount(foundset);

Where does your vtotalsize in the loop come from (or do I overlook something)?

you can also do: for ( var i = 0 ; i <= controller.getMaxRecordIndex() ; i++ )

BTW, to make your life a little better/easier.
I would work with either the controller or the foundset and not mix working with both.