Upsert capability - Check for existing and update before creating new elements

Started by jsandman77, April 20, 2021, 10:42:06 AM

Previous topic - Next topic


Hi there, is there a code snippet somewhere that shows the best way to check for an existing element by ID to do an upsert rather than create a new element? I went through the examples and couldn't find one that does this. Thoughts?

Phil Beauvoir


you could use the ID selector to get an element:

var element = $("#id-1234")

if "element" is returned or is null then you can proceed on that basis.
If you value and use Archi please consider making a donation. :-)


Thanks Phil. Doing that already.

I am using the code example to export / import to a csv and have the properties show up as columns. Unfortunately, the import duplicates everything so I was looking to tweak it so that it would update all of the properties when an element id is already found.

Is there a "round trip" set of scripts where you can export to a CSV, do some bulk updates to properties and then re-import to update the model?

Phil Beauvoir

Sounds like a problem in the logic of the code. When parsing the CSV file, if you are able to get an element by its ID then you can update its name, documentation, properties etc. If the element does not exist then it's up to the code whether to ignore it or create a new element. Perhaps the code example you are using needs more adjustment to suit your case?
If you value and use Archi please consider making a donation. :-)

Jean-Baptiste Sarrodie

If you value and use Archi, please consider making a donation!
Ask your ArchiMate related questions to the ArchiMate Community's Discussion Board.