Delete Record Method where ID field starts with 'E'

I need to test in the method if the employee field (emplid) starts with the letter ‘E’. If so, then it’s ok to delete that record.

//Test to verify if person is not a City of Hope Employee

if (emplid == 'E%'){

	var btn = globals.gDialog_Warning('Are you sure you want to delete ' + first_name + ' ?');
		if(btn == 'OK'){
		controller.deleteRecord()
		}

}
else {
	plugins.dialogs.showErrorDialog('City Of Hope', 'Cannot delete ' + first_name + " " + last_name ,  'Close');
}

Where am I going wrong? :?

You can’t say ‘E%’ in the if. You just have to check if the left-most character is an “E”:

if(utils.stringLeft(empid,1) == 'E')
{
     var btn = globals.gDialog_Warning('Are you sure you want to delete ' + first_name + ' ?');
      if(btn == 'OK'){
      controller.deleteRecord()
      }

}
else {
   plugins.dialogs.showErrorDialog('City Of Hope', 'Cannot delete ' + first_name + " " + last_name ,  'Close');
}

OR - use the JavaScript function:

if(empid.substr(1,1) == 'E')
{
     var btn = globals.gDialog_Warning('Are you sure you want to delete ' + first_name + ' ?');
      if(btn == 'OK'){
      controller.deleteRecord()
      }

}
else {
   plugins.dialogs.showErrorDialog('City Of Hope', 'Cannot delete ' + first_name + " " + last_name ,  'Close');
}

davidaarong:
Where am I going wrong? :?

I would say right at the beginning:

if (emplid == 'E%'){ ...

The SQL wildcard % is not a wildcard you can use in JavaScript.
You should use the following code:

if ( utils.stringLeft(emplid, 1) == "E" ){ ...

Hope this helps.

davidaarong:

if (emplid == 'E%')

Here. That should be:

if(utils.stringLeft(emplid, 1) == 'E')

See! it must be true! ;)

You’re always quicker than me… ;)

wow… you guys are quick!

Thank you Bob, Robert & Nicola

It’s so much easier if you know what you’re doing.
:D