Auto IDs
Auto IDs
(OP)
Hello, again!
I have a table with your standard Update window and procedure that works fine. When a new record is created, the ID field is incremented by one in the new record automatically.
Now I have some Embedded code trying to create a new record manually in the same table:
TABLE1:Field1 = TABLE2:Field1
...
ADD(TABLE)
I'm not specifying the TABLE:ID field assuming the system would increment the value automatically. But, the new record is created and the assigned values are saved to each field -- except the ID field which is always 0.
I'm now assuming I have to specify TABLE:ID = -- but to what?
I have a table with your standard Update window and procedure that works fine. When a new record is created, the ID field is incremented by one in the new record automatically.
Now I have some Embedded code trying to create a new record manually in the same table:
TABLE1:Field1 = TABLE2:Field1
...
ADD(TABLE)
I'm not specifying the TABLE:ID field assuming the system would increment the value automatically. But, the new record is created and the assigned values are saved to each field -- except the ID field which is always 0.
I'm now assuming I have to specify TABLE:ID = -- but to what?
RE: Auto IDs
You may use this code in place of add(<tableName>)
CODE
Access:<tableName>.Insert()
This should do it
Regards
RE: Auto IDs
That code looks odd to me. I got 4 Syntax Errors when I compiled the program with those recommended changes.
We have Clarion 5. Is that code only supported in a higher version?
RE: Auto IDs
regards
RE: Auto IDs
Just Access:<tableName>.Insert() should be enough as PrimeAutoInc might add a empty row/record.
Regards
RE: Auto IDs
==============================================================================
! Create New Prospect
! First, check if not flagged Selected or flagged Ignore
IF CO:SalesProspectSelected = 0 OR CO:SalesProspectIgnore = 1
MESSAGE('"' & CLIP(CO:CompanyNameLong) & '" is not flagged as SELECTED or flagged as IGNORE','ERROR: Cannot Create New Prospect')
ELSE
! Select Portfolio
DO SyncWindow
GlobalRequest = SelectRecord
BrowsePortfolioNames
LocalRequest = OriginalRequest
DO RefreshWindow
IF MESSAGE(CLIP(CO:CompanyNameLong) & ' to ' & CLIP(SPORT:Salesperson) & ' - ' & CLIP(SPORT:Name ) & '?','Assign...',ICON:Question,BUTTON:Yes+BUTTON:No,BUTTON:Yes) = BUTTON:Yes
SLSPROSP:PortfolioID = SPORT:ID
SLSPROSP:PortfolioName = SPORT:Name
SLSPROSP:Salesperson = SPORT:Salesperson
SLSPROSP:CompanyCode = CO:Company
SLSPROSP:CompanyPriority = CO:CoPriority
SLSPROSP:ClientRelationship = '
SLSPROSP:DateAddedtoPortfolio = TODAY()
SLSPROSP:AddedToPortfolioBy = Usr:UserName
SLSPROSP:DateCreated = TODAY()
! ADD(SALESProspects)
Access:SLSPROSPECTS.Insert()
! Update Company, if no Error
IF ERROR() = '
CO:SalesProspectAssigned = 1
CO:SalesProspectAdded = TODAY()
PUT(COMPANY)
END
! GlobalRequest = ChangeRecord
! UpdatePipelineOverview
DISPLAY()
ForceRefresh = True
DO RefreshWindow
END
END
==============================================================================
And here is the compile window results:
Making sales010.obj (sales 010.clw changed)
Making sales010.clw
(sales010.clw 316,37) Syntax error: Field not found:INSERT
(sales010.clw 316,17) Syntax error: Unknown procedure label
RE: Auto IDs
You are using the LEGACY template - Access:<tableName>.Insert() is ABC.
Declare an ALIAS for the SALESProspects and use the ALIAS file to find the next ID. Do a loop check for duplicates in case two users are trying at the same time.
CODE
ADD(SALESProspects)
IF ERRORCODE() = 43
<IDColumn> += 1
CYCLE
ELSIF ERRORCODE()
!handle error
END
BREAK
END
Regards
RE: Auto IDs
Correction. It should be IF ERRORCODE() = 40 ! DupKeyErr ...
Regards