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

You are mixing the currentcontroller and the controller.

The currentcontroller lives in a ‘global scope’, the controller is the controller of the form that you are on.

Especially when working in a forms in tabs will cause issues.

When these methods are form based I would only use the controller.

Hi Marcel,

I know that I was previously using currentcontroller and controller in the same method. However, I have just tried setting the method up using only controller, but it still deletes from all forms including ‘birthstones’. This is despite the fact that there is a condition in the method, which is supposed to prevent ‘birthstone’ records from being deleted. The code showing this is below:

var thecurrentform = controller.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’ve also tried doing the same thing, but using only the global currentcontroller instead of the local controller, but still have the same problem. Once again, the code showing this is 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')
	{
		currentcontroller.deleteRecord();
	}
}

Basically, for some strange reason the system seems to be completely ignoring the ‘if’ condition in this method. I’ve never seen anything like this before. It just doesn’t make sense.

I hope you have some further suggestions on this.

As I showed at the top of my original message, conditions work fine when I’m adding records. I’m adding records in a global method, with separate conditions for each form. I use the currentcontroller to access methods throughout that method.

Craig

so, what when you do an application.output (or whatever debugging method you use).
Is the name what you expect it to be?

Hi Marcel,

I’ve used the debugger to find the value of ‘thecurrentform’ variable in the delete method. It is equal to ‘birthstones’, so it looks as though the right form has been found.

Craig

hmm, suggestion: simply type the complete ‘if’ line again to be sure you have not accidentally typed a control character in the word(s)…

Hi Marcel,

I tried re-typing the condition, but it made no difference. I still get the same problem.

The condition is very straightforward anyway, so I don’t think that can be the problem.

Craig

ok, create a small sample solution and see what happens then.

There is something wrong and, since you already said it, the condition is pretty straight forward stuff it can’t be that.

Hi Marcel,

OK, I’ll give a try and see what happens. However, I wont get around to doing it for a while, as I’m busy with other things at the moment. Therefore you wont see any details of results for the time being.

I’ll put something up here to let you see what’s happened, when I eventually get it done. Thanks for all your assistance with this. Hopefully, the problem will be fixed soon.

Craig

No hurry, it is your issue :)

Petty I could not (yet) be of more help!