Use of RETURN in an IF Statement

I’m a newbie to Sevoy and programming in general. I’ve created the following script below so the user can save an email attachment to the File table. The scrip looks to see if a file with the same name exists and if so prompts the user to either rename the file or to cancel saving the attachment.

My question is that I have used RETURN, when the user hits the cancel button. Is this right? THe scrip seems to work fine. However, what are the ramifications of the script not exiting? Is there an alternative method that is more elegant?

Many thanks

MerMer

//Purpose of script is that it appends a copy of the email attachment to the FILES table

var FileName = filename;
application.output(filename);

//search to see if filename exists in the Files table
forms.files.controller.find();
forms.files.filename = FileName;

//returns the number of records found that match the filename
var recordCount = forms.files.controller.search();

application.output(recordCount);
//if file with the same name exists then dialogue is given to user asking for new name

if (recordCount != 0)
{
var thePressedButton = plugins.dialogs.showInfoDialog(‘Saving An Email Attachment’, ‘There is already a file with the same name on the system, click RENAME to save the file or Cancel to quit’,‘Rename’,‘Cancel’);
application.output(thePressedButton);

if (thePressedButton == ‘Cancel’)
{
application.output(‘cancel has been pushed’);
return; //this works but the scrip is not exited is this a problem?
}
else if (thePressedButton == ‘Rename’)
{
application.output(‘Rename has been pushed’);
var fileNameInput = plugins.dialogs.showInputDialog(‘Saving an email attachment’,‘Enter the new file name’);
}
}
application.output (fileNameInput);
forms.files.controller.newRecord(true);
forms.files.filedescription = filedescription;
forms.files.filename = filename;
forms.files.filebody = attachment;
forms.files.filesize = filesize;
forms.files.source = source;
forms.files.companyid = companyid;

// dialogue box asks for file description.
var inputFileDescription = plugins.dialogs.showInputDialog(‘Saving Email Attachment’,‘Enter a File Description’);
if (inputFileDescription != null)//if a description has been entered.
{
forms.files.filedescription = inputFileDescription;
}

//if the name of the file has been changed then this is updated to the new name//
if (fileNameInput != null)
{
forms.files.filename = fileNameInput;
}

forms.files.controller.saveData()

return will stop the current script!

if you call from another script, it will return to that script.
So I see no problem here!