Form identification problem

Hi,

My name is Craig Campbell, I work with Bevil at Templeton-Smith Ltd.

I have a problem when it comes to identifying forms in Servoy methods. I have code that identifies the form correctly when I’m creating a new database record. However, the same code wont work when I’m trying to control record deletion.

A simplified version of my code for adding a new record is listed below:

var thecurrentform = currentcontroller.getName();

if (thecurrentform == 'birthstones')
{
	currentcontroller.newRecord();
	forms.birthstones.create_related_record();
}

The actual code in my method has conditions for a large number of forms, but you don’t need to see all that.

The code for controlling record deletion is listed below:

var thecurrentform = currentcontroller.getName();

if (thecurrentform == 'birthstones')
{
	// Don't do anything
}
else
{
	var thePressedButton = plugins.dialogs.showWarningDialog('Are you sure',																					 										'Are you sure you want to delete the selected\n' +																									'line. This cannot be undone','OK', 'Cancel');

	if (thePressedButton == 'OK')
	{
		controller.deleteRecord();
	}
}

I just need to prevent records from being deleted from the ‘birthstones’ form. Records can be deleted from all other forms.

Anyway, the condition that checks the form name in the new record method works fine. It always identifies the correct form and a record is then created in the correct database table. However, when it comes to deletion, the record is always deleted even if it’s in the ‘birthstones’ form. Therefore the condition that checks the form name just doesn’t work for some reason.

I’ve even tried setting the delete method up with the following code, but this still deletes records from any form, including the ‘birthstones’ form.

var thecurrentform = currentcontroller.getName();

if (thecurrentform != 'birthstones')
{
	var thePressedButton = plugins.dialogs.showWarningDialog('Are you sure',																						 														'Are you sure you want to delete the selected\n' +																																	 				'line. This cannot be undone','OK', 'Cancel');
	if (thePressedButton == 'OK')
	{
		controller.deleteRecord();
	}
}

I am sure that there is something very simple that causing this problem. I just don’t know what it is. Therefore, please let me know if you can see what’s wrong with my code.

Craig

have you stepped through this in the debugger, or added “application.output(thecurrentform)” to the delete method and checked the console to see what the value you are getting is?

Perhaps, for some reason, the ‘birthstones’ form is not the currentcontroller? (in a tab?) – don’t know, just tossing out ideas.

greg.

Hi Greg,

I’ve checked the value of ‘thecurrentform’ with the debugger and it is ‘birthstones’, so I do have the correct form, if you know what I mean.

Also, the ‘birthstones’ form does have a tab panel in it, but that panel shows a different form with a different name.

My problem is with controlling the deletion of records in the ‘birthstones’ form. I don’t think the other (tab-panel) form is a problem. I am controlling deletion from that (tab-panel) form with a local method.

The code I sent you earlier was from two global methods. (One for creating and another for deleting records). These methods respond to create/delete button clicks from any form in the project. Do I need to control this functionality with local methods?

Craig