Add instance metadata with LUA


trying to register sending peer name in custom metadata when new instance is stored :


function OnStoredInstance(instanceId, tags, metadata, origin)
    local PeerName
    ... (get peer name from orthanc config with origin.RemoteIp)

    RestApiPut('/instances/' .. instanceId .. '/metadata/PeerName', PeerName, true)


but the new metadata is not set, and log reports error :

Lua: Accessing an inexistent item

Lua: Error in RestApiPut() for URI: /instances/…/metadata/PeerName

Why is the item inexistant ?
It seems that OnStoredInstance method is called before the instance is effectively stored in orthanc database.
How can I set custom metadata when instance is stored ?


The “/instances/…/metadata/PeerName” is inexistent if you have not bound the string “PeerName” to an integer in the “UserMetadata” option of the Orthanc configuration file.

Note that you could use directly an integer above 1024 (if you don’t care about seeting a symbolic name for the metadata), for instance:

function OnStoredInstance(instanceId, tags, metadata, origin) RestApiPut('/instances/' .. instanceId .. '/metadata/1024', instanceId, true) end

I have checked, and the “OnStoredInstance” callback effectively has access to the Orthanc database.


Oh, that’s right : I forgot this UserMetadata stuff, thank you !