Move records without losing Meta-attributes with STK 3.1
Hi,
Here is a question I got from a customer using Python STK 3.1
My Goal is to move existing records in the correct folder based on the attribute “Heat Treatment Type” ’s value.
In the example below, if the two records have the value “Stress Relieved”, they should be moved to the corresponding folder:
I have to do that for multiple tables and multiple records. I believe using the Record Manipulator would be time consuming so I started using the Granta MI Scripting Toolkit.
So far, I was able to copy the record to the correct folder and delete the old one using the dataImportService & DeleteOrWithdrawRecord but this is not satisfying as I am losing the original pseudo-attributes like the date the record was created or the author etc.
Do you have any suggestions ?
Many Thanks,
Mickaël
Best Answer
-
Using the STK you are not currently able to move a record without losing the metadata, as you observed you can copy a record using the Foundation Layer
DataImportService
There is a service you can use, but you will need to use something like requests, as there is no python client at present. To see the documentation for this service you can navigate to https://my.mi.server/mi_servicelayer/RecordManipulator/v1.svc/Help.
Here's an example of a short script that should allow you to move a record, targeted against the MI Training database. It should move the T6 titanium record from the 7075 folder to the parent 7000-series (Zn-alloyed) folder in the MaterialUniverse table.import requests from requests.auth import HTTPBasicAuth
db_key = "MI_Training" record_history_to_move = "c0692c05-6dc1-4e58-8271-dc5d9815018b" new_parent_history_guid = "3cc2d114-e9db-42bf-acc7-05f16fad617d" user_name = "MY_USERNAME" password = "MY_PASSWORD" hostname = "my.mi.server" manipulator_url = f"http://{hostname}/mi_servicelayer/RecordManipulator/v1.svc/move" request = {
"DatabaseKey": db_key,
"NewParentHistory": new_parent_history_guid,
"RecordHistory": record_history_to_move
}
authenticator = HTTPBasicAuth(user_name, password=password)
response = requests.post(manipulator_url, json=request, auth=authenticator) print(response)For production use you will want to consider using HTTPS, and not using basic authentication of course!
2
Answers
-
@James Derrick can you give some direction to who might know this?
0 -
@Doug Addy presumably you could do it if you manually copied everything over (including the meta attribute data) and deleted the source record?
0 -
You could copy the actual data for sure, but you would lose the traceability of who created the record and when etc.
1 -
I've been asking myself the same, so thanks Doug for this one! However, it would be really great if a move function could be integrated in a future release of STK as this workaround feels quite a bit "hacky" )
0