Code doesn't work with build 320

I have a form People with a tab panel on it called Addresses. The People table has a field on it called id_addresses_mailing which holds the primary mailing address id for this person. There is a calculated field on the addresses form called PrimaryAddress which compares the address id in the people table with the address id in the current address record and if they match, sets the PrimaryAddress to true.

That all works fine.

If the user clicks on the PrimaryAddress field I have some code which checks to see if there is a different address set as primary and if so pops up a message box asking the user if they want to change the primary address. If they say yes, the PrimaryAddress field is set to true and the address id in the people table is updated.

All of this worked fine with build 319 and prior, but does not work any longer with build 320.

With build 320, if the user first clicks into the address record and then clicks on the PrimaryAddress field, the code runs fine, BUT if they are on one address and then click directly onto the PrimaryAddress field in a different record – it doesn’t work (but does in build 319 and prior).

Here is a copy of the code that runs on the onDataChange event of the PrimaryAddress field.

if ((forms.people.id_addresses_mailing > 0) && (PrimaryAddress == 1) && (forms.people.id_addresses_mailing != id_addresses_mailing)) {
	var myMsg = "The primary address for this record has already been set to Address #" + forms.people.id_addresses_mailing + ".  Are you sure you want to change it?"
	var retVal = plugins.dialogs.showQuestionDialog( "Primary Address Already Set",  myMsg ,  'Yes',  'No',  'Cancel')

	if (retVal == 'Yes') {
		forms.people.id_addresses_mailing = id_addresses_mailing
		forms.people.controller.saveData()
		databaseManager.refreshRecordFromDatabase(forms.people.people_have_addresses_mailing, -1)
	}
	else {
		PrimaryAddress = 0
	}
}
else {
	forms.people.id_addresses_mailing = id_addresses_mailing
}

Any help that you can give to resolve this problem would be appreciated.

I have a small sample that I can send you if need be.

Thanks for your help.

can you send me a example code that demonstraties this.

i am not completely sure what you are saying that doesn’t work anymore. Is it the calculation that doesn’t calculate/update?
Or is it that the script doesn’t run sometimes?

I will send you a sample.

I believe the problem is with the calculation. It still calculates, but I think the timing of when the calculation occurs may have changed.

ahh
2 things did go wrong in youre solution

first you where setting a calculations by hand.. this is not supported. You can’t set a calculation that does return a value itself (return XXX)

second in the calculation you referenced a form.xxx.dataprovider
if you do that then we can’t track the data so some updates are not boiled through…

I made a few changes to the method/calculation
First i made a relation that goes from the mailing->people and use that in the calculation.
Then in the method i don’t set the calc and i don’t test for it, but i use direct the relation/dataprovider check.