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

VBScript: Populate a MultiSelect Property (Text List) from another Multi Select Property (Object List)

I read a lot of threads with similar problems but I think no one asked about this case?

The script should run as a Auto Calculated Value on the Multi Select Property which is based on a Text List.. Can you get me started?

Parents
  • Could you please clarify a bit? I do not understand what you mean by a "Multiselect Property (Text list)"?

    You can have a multiline text property allowing you to add more than one line of text. Is that what you mean?
    If yes, then it seems like the goal is to get the displayvalues from all of the lookup items in your multiselect property, right?

    It should be fairly simple to get the propertyvalue from the multiselect property as lookups and then loop through each of those lookups to get the DisplayValue from each of them while adding that text string to a variable. When the loop is completed you have all the text strings gathered in your variable, and you can use that as output. You can probable add a new line character as well after each added displayvalue to make the result look good.

  • With multiselect property (text list) I mean a multi select property which is based of a non object value list. A multi line text property doesn't do the job cause I want to be able to add a single item from the list to a word or excel document which doesn't work out of the box for a document lookup. So in short I want to mirror a multi select property containing documents to a multi select property containing text values.

    This should act as a workaround for my problem described in the following thread (second problem, last post..):

    https://community.m-files.com/forums-1552881334/f/m-files-clients/6208/office-add-in-get-properties-from-related-document

    I can loop through the multi select lookup and collect the elements but I cannot put them in the second lookup cause it is a different data type..

    This is the code I thought I could use for it but I think the problem is that one lookup is object based and the other based on a text value list and so I need to do some conversion to make it work, that's my problem..

    Dim oLookup : Set oLookup = CreateObject("MFilesAPI.Lookup")
    Dim oLookups : Set oLookups = CreateObject("MFilesAPI.Lookups")
    Dim oAdd
    
    Dim oLookups1: Set oLookups1 = PropertyValues.SearchForPropertyByAlias(Vault, "PD.ZugehoerigeObjekte", True).TypedValue.GetValueAsLookups
    For Each oLookup In oLookups1
    	oAdd = 1
    	For Each oLookup1 in oLookups
    		If oLookup1.DisplayValue = oLookup.DisplayValue Then
    		oAdd = 0
    		Exit For
    		End If
    	Next
    	If oAdd = 1 Then
    	oLookups.Add -1, oLookup
    	End If
    Next
    
    Output = oLookups

  • I do not think that such a solution would be practical in your case, because in practice this means that a list of values must be created dynamically for each document. This speaks of a problem with architecture, as Bright-Idias pointed out in the quoted post. As a workaround, I can suggest the use of multi-line text to be used in the template.
    The code for this must be something like this:

    'Get instance of current object properties
    Dim oPropVals: Set oPropVals = CreateObject("MFilesApi.PropertyValues")
    Set oPropVals = Vault.ObjectPropertyOperations.GetProperties(ObjVer)
    
    'Get property IDbyAliase
    Dim iPDZugehoerigeObjekte : iPDZugehoerigeObjekte = Vault.PropertyDefOperations.GetPropertyDefIDByAlias("PD.ZugehoerigeObjekte")
    
    'Get chosen items as text
    szPDZugehoerigeObjekte = oPropVals.SearchForProperty(iPDZugehoerigeObjekte).TypedValue.DisplayValue
    
    'Splitting by ;
    arrPDZugehoerigeObjekte = Split (szPDZugehoerigeObjekte, ";")
    
    'Convert Array to multiline string
    For i = 0 To UBound(arrPDZugehoerigeObjekte)
    	szPDTemplateZugehoerigeObjekte = szPDTemplateZugehoerigeObjekte & i + 1 & ". " & arrPDZugehoerigeObjekte (i) & vbCrLf
    Next 
    
    'Remove Extra new line
    If Len (szPDTemplateZugehoerigeObjekte) > 0 Then 
    	szPDTemplateZugehoerigeObjekte = Left (szPDTemplateZugehoerigeObjekte, Len(szPDTemplateZugehoerigeObjekte) - 1)
    End If 
    
    OUTPUT = szPDTemplateZugehoerigeObjekte

    This, of course, would only allow placing each selected value on a separate line

Reply
  • I do not think that such a solution would be practical in your case, because in practice this means that a list of values must be created dynamically for each document. This speaks of a problem with architecture, as Bright-Idias pointed out in the quoted post. As a workaround, I can suggest the use of multi-line text to be used in the template.
    The code for this must be something like this:

    'Get instance of current object properties
    Dim oPropVals: Set oPropVals = CreateObject("MFilesApi.PropertyValues")
    Set oPropVals = Vault.ObjectPropertyOperations.GetProperties(ObjVer)
    
    'Get property IDbyAliase
    Dim iPDZugehoerigeObjekte : iPDZugehoerigeObjekte = Vault.PropertyDefOperations.GetPropertyDefIDByAlias("PD.ZugehoerigeObjekte")
    
    'Get chosen items as text
    szPDZugehoerigeObjekte = oPropVals.SearchForProperty(iPDZugehoerigeObjekte).TypedValue.DisplayValue
    
    'Splitting by ;
    arrPDZugehoerigeObjekte = Split (szPDZugehoerigeObjekte, ";")
    
    'Convert Array to multiline string
    For i = 0 To UBound(arrPDZugehoerigeObjekte)
    	szPDTemplateZugehoerigeObjekte = szPDTemplateZugehoerigeObjekte & i + 1 & ". " & arrPDZugehoerigeObjekte (i) & vbCrLf
    Next 
    
    'Remove Extra new line
    If Len (szPDTemplateZugehoerigeObjekte) > 0 Then 
    	szPDTemplateZugehoerigeObjekte = Left (szPDTemplateZugehoerigeObjekte, Len(szPDTemplateZugehoerigeObjekte) - 1)
    End If 
    
    OUTPUT = szPDTemplateZugehoerigeObjekte

    This, of course, would only allow placing each selected value on a separate line

Children
  • Hi Ne0Tr0n, I think my Idea could work, cause it would bei the same shared list for every object.. Only problem i see is that this list could get really long but i will see If it affects performance.. Maybe i have to state that i'm building a vault with Only one object type (Document but renaimed to Object). I think class groups and properties are enough for differencing objects and this approach gives me a lot of extra flexibility.. Can you help again with the solution i mentioned? Thank you very much!