Jump to content
Developer Wiki and Function Reference Links ×

Renaming a field in an existing record format?


Recommended Posts

Is there a Vectorscript function to give a new name to a field in an existing record format?

 

I'm really hoping that something with a signature like `FUNCTION SetFldName(recFormatHd : HANDLE; index : INTEGER; newName : STRING) : BOOLEAN;` exists somewhere, notwithstanding it not existing in the docs ... ie. the apparently missing setter half of `GetFldName(recFormatHd : HANDLE; index) : STRING;`.

 

On reflection, I can imagine that this could cause some potential mayhem with existing record instances. But, my ability to rename a field from the UI suggests that it's perfectly do-able, but not exposed to Vectorscript.

 

I'm speculating that that `GetParamName(size_t paramIndex)` hanging off of VWRecordFormat in the SDK's VW foundation classes is what the Vectorscript `GetFldName` is under the hood. But that class has only a `SetParamLocalizedName` ... no `SetParamName` so there doesn't look to be anything I could publish to Vectorscript with an SDK library.

Link to comment

Ryan,

   I don't think you can do it directly. The best I can suggest is to use a brute force approach.

 

1) create a new record with the fields of the old record and the one renamed as you like.

2) move default values from the old record to the new.

3) go through the file and attach the new record to any object that has the old record attached. 

4) move values from the old attached record to the newly attached record.

5) delete the old record format. This should detach all instances in the file, but if you like, remove the old record after you attach and clone the new one.

6) rename the new record to the old record name with SetName(GetObject('NewRecordName'), 'OldRecordName').

7) turn this code module into a procedure so you can use it again without a lot of grief.

 

   Ideally, if you could get a handle to a record field, you could use SetName() on it, but I don't see that as an option in the VS calls.

 

NOTE: If the record is a PIO record, all bets are off. Also, I have no idea how this will affect any worksheet that references the old record. Since the formulae are text based, it may not matter. As with all complex surgeries, try this on a COPY of your file first!

 

Have fun. If you get it to work let me know. I love it when you get to use a bazooka to swat a fly.  🙂

 

Raymond

Link to comment

Hi Raymond--

 

Blerg, this is what I'd feared. Thanks for laying out the approach though. Seems straightforward but a bit more of a nail-biter than I'd like.

 

indiana-jones.thumb.gif.b26b65fe4cad55a81a527e5bd0d2a260.gif

 

Yeah, I'm not sure either that record fields even have handles, or at least not any VS can see.

 

Fortunately it's not a PIO record. The records in question are regular user-attached records on drawing tags, as part of a schedule generator. I do use worksheets as part of the implementation, but (also fortunately) the worksheets aren't the source of truth (the tags/records are) and can be automatically re-generated after the record replacement.

 

Ryan

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...