Jump to content
Salesforce and other SMB Solutions are coming soon. ×

Add/Subtract value to field


macGrrl

Recommended Posts

Trying to increase VOL_ID (number,unique) in script for new record. Tried Set next serial value = VOL_ID+1 which showed next number in sequence.

 

Then if deleting (user changes mind about new record), I want to set the VOL_ID back one number. Tried VOL_ID-1 but that placed the next value of VOL_ID as -1.

 

PS: Did this forum just have a massive changeover in apperance (edit screen)?

Link to comment
Share on other sites

Best thing to do is DO NOT CREATE THE RECORD until the user has CONFIRMED they want it. If it were me I would set up a data entry screen using global variables. With an ADD RECORD button or whatever at the bottom. When they finished filling in the record if they changed their mind and hit CANCEL instead - no harm done. You dump the variables and your VOL_ID stays where it should. If they choose to ADD you then CREATE the NEW RECORD and dump their variables into it.

 

Having said that will VOL_ID+(-1) work?

Link to comment
Share on other sites

  • 2 weeks later...

Why not use:

Max(AllRecords::SerialNumber)+1

...when creating a new record???

 

Much simpler (and you don't have to mess with decresing the VOL_ID when someone deletes a record).

Link to comment
Share on other sites

Most conveniently works the script "new record":

In this case you can change vol_id as want.

This script is:

New Record Request

vol_Id=1

loop

.... exitloopif(isempty(self_relation_on_vol_id::vol_id))

.... set field(vol_id,vol_id+1)

endloop

Now if you validate vol_Id as unique, you can even change it.

Link to comment
Share on other sites

[ QUOTE ]

Using Get(TotalRecordCount) will cause duplicates if records are ever deleted.

 

[/ QUOTE ]

 

Perhaps I haven't been clear enough.

My suggestion was meant to be used when deleting the new, unwanted record.

 

If other records can be deleted, then what's the point in insisting on a consecutive sequence of serial numbers?

Link to comment
Share on other sites

In addition to the possibility of old records being purged at some point, there is the problem of duplicates happening in a multi-user environment when using Get(TotalRecordCount):

 

User 1 creates the 10th record, with ID = 10.

User 2 creates the 11th record, with ID = 11.

User 1 aborts, deleting record ID 10.

There are now 10 records, the next ID is reset to 11.

User 3 creates the 11th record, with ID = 11.

Now there are two records with ID = 11.

 

Of course, using Max() or Last() is still not the best solution, as these could have skipped IDs in a multi-user environment.

Link to comment
Share on other sites

None of these is the best solution. That's the trouble with answering the question "as is". In a multi-user environment, I'd go with the Digital Man's suggestion.

 

I use a somewhat similar method myself, in a single-user environment:

There is always one empty record in the file. When the user clicks New.., the file goes to the empty record. If the user decides to Add Record (Are you sure?), the record is marked as Registered, and a new empty record is generated.

 

Because this is strictly single-user environment (runtime), I was able to avoid the extra global fields (and the hassle of getting them to validate).

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.



×
×
  • Create New...

Important Information

Terms of Use