I need to get the users ID using the username information through VBScript

I'm creating a user via vbscript below:

"Option Explicit

Dim oServerApp: set oServerApp = CreateObject("MFilesAPI.MFilesServerApplication")
oServerApp.Connect 2, "user", "password", "SERVERNAME", "ncacn_ip_tcp", "localhost", "2266", "DEMO VAULT NAME", false
Dim oVault: Set oVault = oServerApp.LogInToVaultAdministrative(VaultGUID)

Dim oEmail: oEmail = PropertyValues.SearchForProperty(1089).TypedValue.DisplayValue

Dim oLoginAccount: Set oLoginAccount = CreateObject("MFilesAPI.LoginAccount")
Dim oUserAccount: Set oUserAccount = CreateObject("MFilesAPI.UserAccount")


oLoginAccount.AccountType = MFLoginAccountTypeMFiles
oLoginAccount.LicenseType = MFLicenseTypeConcurrentUserLicense
oLoginAccount.EmailAddress = oEmail
oLoginAccount.Enabled = True
oLoginAccount.UserName = "user-" & oEmail


oServerApp.LoginAccountOperations.AddLoginAccount oLoginAccount, "Testepassword"

oUserAccount.Enabled = true
oUserAccount.InternalUser = true
oUserAccount.LoginName = "omega-" & oEmail


'oVault.UserOperations.ModifyUserAccount oUserAccount
oVault.UserOperations.AddUserAccount oUserAccount

oServerApp.Disconnect()"

Now you need to set this user created on a property of type list that points to M-files users.

Dim oPropVal : Set oPropVal = CreateObject("MFilesAPI.PropertyValue")
oPropVal.PropertyDef = 1150
oPropVal.TypedValue.SetValue MFDatatypeLookup, ??????
Vault.ObjectPropertyOperations.SetProperty ObjVer, oPropVal

I know the "MFDatatypeLookup" requires the ID.

How to get the userid I created?

Can anyone provide a code example?

Parents Reply
  • Thanks for your help! I followed your directions including this script in the following state, but the error occurred:

    Cliente Ativo, StateAction, 5, Object doesn't support this property or method: 'Vault.UserOperations.SearchForUserAccount' (0x80040008)
    MErrorHelper.cpp, 2457, Object doesn't support this property or method: 'Vault.UserOperations.SearchForUserAccount' (0x80040008)

Children
  • Please, provide your script.

  • Below is the script that is in the first state to create the useraccount (Note: I changed the variable oVault to Vault, because the execution and changes must occur in the current vault):

    Option Explicit

    If ObjVer.type = 111 then

    Dim oServerApp: set oServerApp = CreateObject("MFilesAPI.MFilesServerApplication")
    oServerApp.Connect 2, "user", "password", "servername", "ncacn_ip_tcp", "localhost", "2266", "Demo Vault", false
    Dim Vault : Set Vault = oServerApp.LogInToVaultAdministrative("{VAULTGUID}")

    Dim oEmail : oEmail = PropertyValues.SearchForProperty(1089).TypedValue.DisplayValue

    Dim oLoginAccount: Set oLoginAccount = CreateObject("MFilesAPI.LoginAccount")

    oLoginAccount.AccountType = MFLoginAccountTypeMFiles
    oLoginAccount.LicenseType = MFLicenseTypeNone
    oLoginAccount.EmailAddress = oEmail
    oLoginAccount.Enabled = True
    oLoginAccount.UserName = "omega-" & oEmail


    oServerApp.LoginAccountOperations.AddLoginAccount oLoginAccount, "password"

    Dim oUserAccount: Set oUserAccount = CreateObject("MFilesAPI.UserAccount")

    oUserAccount.Enabled = true
    oUserAccount.InternalUser = true
    oUserAccount.LoginName = "omega-" & oEmail

    Vault.UserOperations.AddUserAccount(oUserAccount)

    oServerApp.Disconnect()
    End If

    And this is the script that is in the second state to set the useraccount created in the previous state in property 1150:

    Option Explicit

    Dim oEmail: oEmail = PropertyValues.SearchForProperty(1089).TypedValue.DisplayValue

    Dim oUserAccount : Set oUserAccount = Vault.UserOperations.SearchForUserAccount("omega-" & oEmail)

    Dim oPropVal : Set oPropVal = CreateObject("MFilesAPI.PropertyValue")
    oPropVal.PropertyDef = 1150
    oPropVal.TypedValue.SetValue MFDatatypeLookup, oUserAccount.ID
    Vault.ObjectPropertyOperations.SetProperty ObjVer, oPropVal

  • Radu Moca and Ne0Tr0n, thank you so much for your help!
    I managed to set the information in the User List property (1150) with the script below:

    Opção Explícita

    Dim oEmail: oEmail = PropertyValues.SearchForProperty (1089) .TypedValue.DisplayValue

    Dim oPropertyDef: Set oPropertyDef = Vault.PropertyDefOperations.GetPropertyDef(1150)
    Dim ValueListID: ValueListID = oPropertyDef.ValueList
    Dim ValueListItem
    Dim ValueListItems: Set ValueListItems = Vault.ValueListItemOperations.GetValueListItems(ValueListID)
    For Each ValueListItem in ValueListItems
    If ValueListItem.Name = "omega-"&oEmail Then
    'Set your property

    Dim oPropVal : Set oPropVal = CreateObject("MFilesAPI.PropertyValue")
    oPropVal.PropertyDef = 1150
    oPropVal.TypedValue.SetValue MFDatatypeLookup, ValueListItem.ID
    Vault.ObjectPropertyOperations.SetProperty ObjVer, oPropVal

    Exit For
    End If
    Next