Jump to content

script to add surrogate key to existing files

This topic is 6527 days old. Please don't post here. Open a new topic instead.

Recommended Posts

  • Newbies

Hi....I have an issue with adding a surrogate key for already existing database. I have crated a treatment key as a surrogate key for all values of medical record number..but am unable to populate it with incrementing numbers. Tha maximum I could get to was...populating the treatment key with same value. Plz help me to change these numbers to incrementing numbers...rather than same vakue.

I do not know which category to use in the scriptmaker to initiate a count to increment numbers by one after each loop.

Plz help me out with this!!!

Version: v6.x

Platform: Windows XP

Link to comment
Share on other sites

If I'm understanding your question correctly:

1) Define a global number field "LoopCounter"

2) show all records you want to set the surrogate in and sort the way you want them to increment.

3) The important parts of the script:

Set Field ["LoopCounter", "1"]


SetField ("surrogateKey", "LoopCounter")

Exit Loop If ["Status (CurrentRecordNumber) = Status (CurrentRecordCount)"]

Goto Record/Request/Page [Next]

Set Field ["LoopCounter", "LoopCounter + 1"]

End Loop

Is this what you wanted to do?

Link to comment
Share on other sites

  • Newbies

Thanks ...it did help a lot....i just had to reassign the value of loopcounter as the surrogate key and take the next value of loopcounter as previous record of loopcounter +1.

that did it!


Link to comment
Share on other sites

I didn't mention this in my first post, but:

Look at the script step Replace Contents. It replaces the contents of a field with a value which can be a serial #, a calculation, etc. It works across all records in the found set. It will be faster than the loop. In your case it would look like:

Replace Contents [No dialog, "SurrogateKey", "Serial numbers"]

Things to note:

1) It operates on records in the Found Set, if you want to do this for all records be sure to include a Show All records step before.

2) It uses the current sort order, so make sure the records are sorted the way you need.

3) Check the No dialog if you don't need to change anything in the replace dialog (like starting serial #, etc).

Version: v7.x

Platform: Mac OS X Panther

Link to comment
Share on other sites

This topic is 6527 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...

Important Information

By using this site, you agree to our Terms of Use.