problem with onDataChange method attached to comboBox

Maybe this isn’t actually a problem, but I’m still a newbie so I don’t know. As one of my first projects, I’m putting together a simple contact manager so that I can wean some of our users off Now Contact. I’m trying to duplicate the way Now Contact can attach a keyword to a contact. I put the keywords into a value list, and attached them to a comboBox. In the onDataChange method, I put the code below. It is supposed to add the keyword to the contact if it doesn’t already exist, and delete the keyword if it does exist. The code does all that, but at the end, I want it to reset the global variable the combo box is connected to back to ‘Select…’ It won’t do it. Whenever I chose an option from the comboBox, it adds or deletes the keyword correctly, but then it remains set to whatever I selected, it doesn’t reset to ‘Select…’. Maybe its just not possible to change the underlying global variable in the onDataChange method? If so, is there a better way to do this?

Thanks for your help!

-Shane

function onDataChangeKeyword(oldValue, newValue, event) {
	
	var keyWordCount = contacts_to_keywords.getSize();
	var keyWordExists = 0;

	for (var i = 1; i <= keyWordCount; i++ )
	{
		contacts_to_keywords.setSelectedIndex(i);
		
		if (contacts_to_keywords.keyword == newValue)
		{
			keyExists = 1;
			contacts_to_keywords.deleteRecord();
		}
	}

	if (keyWordExists == 0)
	{
		contacts_to_keywords.newRecord();
		contacts_to_keywords.keyword = newValue;
	}
	
	var v_SelectKey = 'Select...';
	return true
}

Hi Shane,
I don’t think there is that kind of limitation in the onDataChange event triggered method.

But what is the dataprovider of your select exactly? You talk about a global variable but I don’t see you setting it in your snippet.
If the variable that is linked to your select is v_SelectKey (global or not), then you need to get rid of the ‘var’ keyword in front of it, because if you use it, then the variable will be scoped as local to the function (it is not visible outside of it).

So if you have a v_SelectKey form variable, do:

v_SelectKey = 'Select...';

if it is a global, do:

globals.v_SelectKey = 'Select...';

and this should work!

Hope this helps,

Thanks a ton Patrick, that did the trick.

You were right, it was a form variable, not a global. I guess I thought since at the top of my .js file, it said var v_SelectKey, I had to use the same syntax in the method below. I didn’t realize it was initializing it locally for the whole form, but in the methods below, it would mean it was only referencing it for the method.

-Shane