setting multiple records with the same valuelist choice

Hi all.

I have a checkbox field with a valuelist which is set depending on which user is using the system. I need to be able to apply the same checkbox value to, or remove the same value from more than one record simultaneously.

I don’t know if there is an easier way to do it than looping through the foundset, and doing a string operation on the valuelist field.

Would be grateful for any pointers…

Thanks

Bevil

Database Manager > JSFoundSetUpdater

var fsUpdater = databaseManager.getFoundSetUpdater(foundset)
fsUpdater.setColumn('row_status_expanded',1)
fsUpdater.setColumn('row_status_show',1)
fsUpdater.performUpdate()

Hi David

Thank you for that. It shows that I can avoid the loop.

However, can I use it with an evaluation of whether my data provider contains my string, and then do a string replace of the text to remove or add the specific valuelist item that has been added (or removed)?

With a loop, I would do the evaluation on each iteration through the loop. With getFoundSetUpdater, it seems that there is no way to run a check during the process?

What I have here is a checkbox that has an arbitrary number of values, say [red, green, blue, brown, orange] , I want to be able to do an ondatachange on a combobox (of the same valuelist) to

‘remove from the list of records’ (some of the foundset may already have blue checked),

or

‘add to the list of records’

It seems that doing a getfoundsetupdater will change my entire dataprovider value without giving a chance to evaluate it…

You are correct, getfoundsetupdater doesn’t allow you to apply logic so you’ll have to loop on the foundset object.

What you’re really looking for is something like the Array.forEach() functional programming helper. foundset.forEach(function(record, index, foundset){ … } ) would do the trick nicely!

Thanks for the help David, you set me on the right path…

For anyone following this particular path, this is what I now have, and how I did it

I didn’t use forEach, Instead I turned my related (has to be related or you lose your previous values when you change value lists) dataprovider, converted to an array, used a splice, and spliced my value into and out of the array depending on whether I was adding or removing it (you have to remember to add the \n ). My array was then converted back to text where I joined the array back together on the \n. It has taken all day, but it works beautifully.

The point of it is that it adds the same checkbox value to a foundset of records - and the valuelists are different depending on the user. You can choose user A, and see all their (enabled) checkbox values, or choose user B and see theirs etc. Once you’ve chosen a user, you can add or remove a particular value to or from the whole foundset. This means that my records can have perpetually saved groups of items - a la metadata. The related record is on the username and the record id, so each user has to have a join record for every row in the table.

My code, to add the checkbox is:

function onDataChange_loop_add_tag_to_foundset(oldValue, newValue, event) {
	
	var vTheTag = globals.g_tag_add_to
	for (var i = 1; i <= foundset.getSize(); i++){
		
		foundset.setSelectedIndex(i)

		if (foundset.getSize() > galleria_administration_to_superuser.tag_warning_size){
			var thePressedButton = plugins.dialogs.showWarningDialog('Warning','You have selected more than ' + galleria_administration_to_superuser.tag_warning_size + ' items to tag, are you sure?','OK','Cancel')
			if (thePressedButton = 'Cancel'){
				return
			}
		}

		if (foundset.works_to_tags_join.getSize()>0){	
			if (foundset.works_to_tags_join.getSize()>1){
				application.ouput('error - more than one related works to tags record!!!')
			}
		}
		else{
		foundset.works_to_tags_join.newRecord(true)
		}
		
		var itemsArray = new Array();
		
		if (works_to_tags_join.all_tags){
		itemsArray = works_to_tags_join.all_tags.split('\n');
		}
		
		
		var index = itemsArray.indexOf(globals.g_tag_add_to);
		if (index < 0) {
		    itemsArray.splice(2, 0, vTheTag);
		}

		var myString = itemsArray.join('\n');
			
		foundset.works_to_tags_join.all_tags = myString
	
	
	
	}
		
	databaseManager.saveData()
}

And to remove the specified check:

function onDataChange_loop_remove_tag_from_foundset(oldValue, newValue, event) {

	var vTheTag = globals.g_tag_remove_from
	for (var i = 1; i <= foundset.getSize(); i++){
		foundset.setSelectedIndex(i)

		
		
		if (foundset.works_to_tags_join.getSize()>0){	
		}
		else{
		foundset.works_to_tags_join.newRecord(true)
		}

		
		var itemsArray = new Array();
		
		
		itemsArray = works_to_tags_join.all_tags.split('\n');
		
	
		var index = itemsArray.indexOf(globals.g_tag_remove_from);
		if (index > -1) {
		    itemsArray.splice(index, 1);
		}

		var myString = itemsArray.join('\n');
				
		
		foundset.works_to_tags_join.all_tags = myString
	
	
	
	}

I initially tried to use just text and string.replace(this, that), but if you have say ‘2014’ as a valuelist value, and ‘2014 accounts’ as another, and you remove 2014 as a string value from all, you end up breaking all the ‘2014 accounts’ values. It had to be an array for this reason.