ken bohnenkamp
25th September 2002, 15:58
I am entering a form field called Car Number (the main table of the form is called Profile). I would like to do an edit to check to see if this number already exists in the Profile table. If it exists I would like to give and error disallowing entry of the number and keep the user at the Car Number field to reenter another number. Can anyone send me the syntax to do this type of logic?

evesely
25th September 2002, 16:25
The main table is "Profile"? I guess that must be the description.

Anyway, you can use the field's check.input section for this. Here, I'll assume the field is fieldnm, the table is tablenm, and the table field is tablefld.


field.fieldnm:
check.input:
select tablenm.tablefld
from tablenm
where tablenm.tablefld = :fieldnm
as set with 1 rows
selectdo
set.input.error("message.number")
endselect


Here, message.number is a valid message that you can add in Maintain Messages. If you don't want to do that, you can use the message() function followed by set.input.error("").

Now, if you plan on doing editing, you may need to limit this check to when you are doing inserts. Otherwise,you will not be able to change your data as you might like. This can be done by checking if update.status = add.set .

There are different variations on this, but that is the general idea.

FransG
25th September 2002, 16:26
Hi,

In Baan IV:


field.car.number:
check.input:
if car.already.exist() then
set.input.error("<message code>")
endif

function domain tcbool car.already.exist()
{
select profile.car.number
from profile
where profile.car.number = :car.number
as set with 1 rows
selectdo
return(true)
endselect

return(false)
}


In BaanERP (in the DAL of the main table):


function extern long profile.car.number.check(long has_changed)
|* function extern long ppmmmxxxx.check(long has_changed)
{
if car.number.exist() then
dal.set.error.message("<message code>")
return(DALHOOKERROR)

return(0)
}

function domain tcbool car.already.exist()
{
select profile.car.number
from profile
where profile.car.number = :car.number
as set with 1 rows
selectdo
return(true)
endselect

return(false)
}