The M-Files Community will be updated on Tuesday, April 2, 2024 at 10:00 AM EST / 2:00 PM GMT and the update is expected to last for several hours. The site will be unavailable during this time.

This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

How to refer to items in a value list by their 'Name'

Hi, I've got some code in a workflow where depending on one source property, we're setting another destination property 'Type'

'Type' is a value list which contains:

Programme, ID = 1

Project, ID = 2

etc

Previously I was doing that via just setting the ID number. I know that Project is ID=2 in the Type value list, so I have that ID number hard coded in the script

However, the vault is due to be deployed to production via content replication rather than transferring an .MFB so we've been told that all ID number references should be avoided and everything needs to use aliases instead, as the ID numbers may get shuffled around in the transition and won't stay in the same order

 

So, How can I avoid using the ID? I know the value in the source property will be 'Project', so do I have to construct a search to find the item within the value list that matches, then I can get the (new) ID number, and use that ID as previously? or is there some better approach

Many thanks

Parents
  • You're correct: replication will make the IDs change.

    You have two options:

    • Search for the value list item by name, then use the ID of the value list item that comes back.
    • Get the item ID by the GUID of the value list item.  I am 90% sure that item GUIDs will stay the same across replication, so your code can look for the known GUID and it should be able to return the correct value item in the production vault.

    I personally don't like to use the value list item name for anything, as it's too easy for someone to say "oh, yes, we now spell it 'Program'", change the value list item name, and all hell opens up.  For that reason - and I will try to double-check about the GUIDs for you - I would probably lean towards the second option.

  • Great, thanks for the info. I'd appreciate confirmation on the GUID idea because we can't currently test this ourselves

    Another approach might be to have 1x Managed Property rule for each different value, and set a static value (choose from list) to each different one?

    Those rules you select from the value list items like a dropdown so you see the name. i think it stores it as a GUID tho in the JSON

  • In general when you configure a vault application (like managed properties), you can choose how the reference is made.  I don't recall exactly, but I think it will default to the GUID (the second dropdown to the right of the property name allows you to choose between GUID and ID).  It's reasons like that which lead me to believe that I am correct about the GUIDs.

    Unfortunately self-doubt has now crept in, so I need to get someone else to confirm...! Joy

    I have put a message on an internal product teams channel.  I'll update the thread when I get a response (probably tomorrow).

  • Heheh yea it defaults to GUID and the other option is something like 263-3, which is valuelistID-valuelistItemID

    If there was aliases available, could have selected those as well. but value list items can't have aliases, which is what makes this all such a pain

    I'm also assuming GUIDs don't change, otherwise it'll break a lot of our Compliance Kit config and we'd have been advised to update that as well

Reply
  • Heheh yea it defaults to GUID and the other option is something like 263-3, which is valuelistID-valuelistItemID

    If there was aliases available, could have selected those as well. but value list items can't have aliases, which is what makes this all such a pain

    I'm also assuming GUIDs don't change, otherwise it'll break a lot of our Compliance Kit config and we'd have been advised to update that as well

Children
  • I just did a quick replication package export of a value list and items from one vault to another.  The IDs stayed the same.  Below is a screenshot showing the snip I took of the source vault, and the data from the target vault after import:

    So, yes, use the GUIDs.

  • Many thanks
    Does your test retain those IDs because they're nicely alphabetalical with no gaps etc?

  • I don't think that makes one bit of difference.

    That said: if you have a local M-Files vault with the exact list you want to use, you could create a replication package containing just that list and its values, export it, and then import it into a blank vault for testing.  That's exactly what I did, but you could test it with your exact structure if you have concerns.

    Edit: having read the response from , then having re-read your post, I realise that I misread it.  As he said said: the IDs happen to be the same in this case, but may not be in yours.  You need to assume that they will be different even though in some cases - especially when replicating into a blank vault - they may happen to end up the same.

  • The ID numbers will change in replication if someone manually adds an item in the receiving vault. This new item will automatically take the next ID available. This ID will then be taken when replication pulls in a new item from the external vault, and the incoming item will have to change ID to the next available number.