<entity-one entity-name="MasterIncentive" value-name="masterIncentive"/> <if-empty field-name="masterIncentive"> <make-value entity-name="MasterIncentive" value-name="newEntity"/> <set-nonpk-fields map-name="parameters" value-name="newEntity"/> <set-pk-fields map-name="parameters" value-name="newEntity"/> <!-- Create the newEntity and if primary key is required back in result, can be set in result here as well--> <else> <!-- Your error message here if the incentive Code already exists --> </else> </if-empty>
I hope this will solve your issue. If I remember correct now a days <set> tag is used instead of field-to-field. On Dec 4, 2007 1:16 PM, nashrul <[EMAIL PROTECTED]> wrote: > > #1 is what i expect.. > > > Vikas Mayur-2 wrote: > > > > 1) Is the incentiveCode is the required field for your form, if yes than > > user has always to enter this code before submitting the form > > and in that case this will be searched in the database if this code > > already > > exists. > > 2) If not and user submits the form than you want the system to generate > > the > > primary key i.e. incentiveCode. > > > > From #1 and #2 what exactly are your requirements. > > > > > > On Dec 4, 2007 9:42 AM, nashrul <[EMAIL PROTECTED]> wrote: > > > >> > >> I have a scheme table for incentive calculation .Table Incentive with > the > >> following fields : > >> > >> <entity entity-name="MasterIncentive" title="Master for Incentive" > > >> <field name="incentiveCode" type="id-ne"/> > >> <field name="maxNo" type="currency-amount"/> > >> <field name="amount" type="currency-amount"/> > >> <prim-key field="incentiveCode"/> > >> </entity> > >> > >> There is a form to create new scheme. > >> When the user fills in the form and enter the submit button.. the > simple > >> method will check, whether the primary key inputted is already used. If > >> it > >> is, it will display an error message "incentive code entered is already > >> used. Use another incentive code". And if it isn't, the simple method > >> will > >> run as usual (). Here is my simple method code.. > >> > >> <simple-method method-name="createIncNewScheme" > short-description="Create > >> an > >> Incentive Scheme"> > >> > >> <!-- add check duplicate --> > >> <field-to-field field-name="incentiveCode" > map-name="parameters" > >> to-map-name="lookupParams"/> > >> <field-to-field string="incentiveCode" map-name="parameters" > >> to-map-name="lookupParams"/> > >> <find-by-primary-key use-cache="true" > >> entity-name="MasterIncentive" > >> value-name="losCode" map-name="lookupParams"/> > >> <if-empty field-name="incentiveCode"> > >> <!-- end check --> > >> <make-value value-name="newEntity" > >> entity-name="MasterIncentive"></make-value> > >> <set-nonpk-fields map-name="parameters" > >> value-name="newEntity"></set-nonpk-fields> > >> <set from-field="parameters.incentiveCode" > >> field="newEntity.incentiveCode"></set> > >> <if-empty field-name=" > >> newEntity.incentiveCode"> > >> <sequenced-id-to-env > >> sequence-name="Hlid" > >> env-name="newEntity.incentiveCode"></sequenced-id-to-env> > >> <else> > >> <check-id > >> field-name="incentiveCode" map-name="newEntity"></check-id> > >> <check-errors></check-errors> > >> </else> > >> </if-empty> > >> <field-to-result field-name="incentiveCode" > >> map-name="newEntity" > >> result-name="incentiveCode"></field-to-result> > >> <create-value > >> value-name="newEntity"></create-value> > >> <else> > >> <add-error><fail-message message="incentiveCode > is > >> already used, use > >> another one"/></add-error> > >> <check-errors/> > >> </else> > >> </if-empty> > >> > >> </simple-method> > >> > >> The problem with this code is that, the simple method keeps storing the > >> new > >> scheme in the table, although it found another record in the table with > >> the > >> same primary key. > >> Could anyone help me ?? > >> Thanks > >> > >> > >> -- > >> View this message in context: > >> > http://www.nabble.com/Simple-method-question%2C-checking-duplicate-primary-key-tf4941048.html#a14144328 > >> Sent from the OFBiz - User mailing list archive at Nabble.com. > >> > >> > > > > > > -- > > Vikas Mayur > > > > > > -- > View this message in context: > http://www.nabble.com/Simple-method-question%2C-checking-duplicate-primary-key-tf4941048.html#a14146126 > Sent from the OFBiz - User mailing list archive at Nabble.com. > > -- Vikas Mayur