Inserting record

Hi,

I have two tables called applicant and employee.here when I click a button in the applicant card all the fields should go into the employee card.At the same time No series of applicant id should transfer No series of as an employee Id.

I have satisfied all this conditions…but now problem is once it is converted into employee ,again if the button is clicked the applicant id should not be converted into employee.

But for me whenever im clicking the button the records are getting transferred.

for that we are maintaining applicant id in the employee table…I am attaching the piece of code…

IF NOT CONFIRM (‘Do you want to convert into employee’) THEN
EXIT ;
IF “Candidate Status”=“Candidate Status”::Selected THEN
BEGIN
IF NOT (emp.GET(“App ID”)) THEN

emp.“No.”:=’’;
IF emp.“applicant id”<>“App ID” THEN
BEGIN
emp.“applicant id”:=“App ID”;
emp.“First Name”:=“First Name”;
emp.“Middle Name”:=“Middle Name”;
emp.INSERT(TRUE)
END
ELSE
MESSAGE(‘ALREADY EXISTS’);
END
ELSE
ERROR(‘Only Selected Candidates can be converted into Employees’);

please suggest us where I have gone wrong…

I guess your code works randomly.

IF NOT CONFIRM ('Do you want to convert into employee') THEN
EXIT ;
IF "Candidate Status"="Candidate Status"::Selected THEN
BEGIN
IF NOT (emp.GET("App ID")) THEN BEGIN // Missing a BEGIN here
emp."No.":='';
IF emp."applicant id"<>"App ID" THEN
BEGIN
emp."applicant id":="App ID";
emp."First Name":="First Name";
emp."Middle Name":="Middle Name";
emp.INSERT(TRUE)
END
ELSE
MESSAGE('ALREADY EXISTS');
END // This end is also missing
END
ELSE
ERROR('Only Selected Candidates can be converted into Employees')

Try this instead

Hi Thomas,

This code works fine only from second click everytime we open the form.

Once the record are inserted whevever we click it should show error .

So please guide us…

What you are missing is that you do expect that the App Id and employee number are the same :

IF NOT (emp.GET(“App ID”)) THEN BEGIN // Missing a BEGIN here

This is in fact not true as far as I understand by the following code:

emp.“No.”:=’’;
IF emp.“applicant id”<>“App ID” THEN
BEGIN
emp.“applicant id”:=“App ID”;
emp.“First Name”:=“First Name”;
emp.“Middle Name”:=“Middle Name”;
emp.INSERT(TRUE)
END

I would run it this way:

IF NOT CONFIRM ('Do you want to convert into employee') THEN
EXIT ;
IF "Candidate Status" = "Candidate Status"::Selected THEN BEGIN
Emp.SETRANGE("applicant ID", "App ID");
IF EMP.ISEMPTY THEN BEGIN
emp."No.":='';
emp."applicant id":="App ID";
emp."First Name":="First Name";
emp."Middle Name":="Middle Name";
emp.INSERT(TRUE);
END ELSE
MESSAGE('ALREADY EXISTS');
END ELSE
ERROR('Only Selected Candidates can be converted into Employees')

If your applicant table and your employee table match with field numbers and field types you could even use the following:

IF NOT CONFIRM ('Do you want to convert into employee') THEN
EXIT ;
IF "Candidate Status" = "Candidate Status"::Selected THEN BEGIN
Emp.SETRANGE("applicant ID", "App ID");
IF EMP.ISEMPTY THEN BEGIN
emp.TRANSFERFIELDS(Rec);
emp."No.":='';
emp."applicant id":="App ID";
emp.INSERT(TRUE);
END ELSE
MESSAGE('ALREADY EXISTS');
END ELSE
ERROR('Only Selected Candidates can be converted into Employees')

Hi Thomas,

Thank you very much…

code is working perfectly…now we came to know where we are going wrong…

once again thank you thomas

Glad that I could help.

Please do not forget to verify the post which helped you to solve your problem.

This credits the experts who helped, earns you points and marks your thread as Resolved so we all know you have been helped.