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

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
  • I'm not a VBScript expert but according to the API reference the AddUserAccount method (https://www.m-files.com/api/documentation/#MFilesAPI~VaultUserOperations~AddUserAccount.html) seems to return the created user account, so you should be able to get the ID from the UserAccount object (https://www.m-files.com/api/documentation/#MFilesAPI~UserAccount.html).

  • Thanks for your help!
    I have no experience with VBscript, could you send me an example script?

  • Hello, I think you need to modify this:

    oVault.UserOperations.AddUserAccount oUserAccount to

    dim userid : userid = oVault.UserOperations.AddUserAccount oUserAccount 

    and then:

    oPropVal.TypedValue.SetValue MFDatatypeLookup, userid    or

    oPropVal.TypedValue.SetValue MFDatatypeLookup, userid.ID

  • Thank you for your help! I made the change and it did not work shows an error.

    In my origianl script when I put "oPropVal.TypedValue.SetValue MFDatatypeLookup, oUserAccount.ID" it creates the Login and User, but when setting the 1150 property, an error occurs informing value "0".

  • can you paste the whole script again here?

    from your response, you partially modified the script.

  • Ok follow:

    Option Explicit

    Dim oServerApp: set oServerApp = CreateObject("MFilesAPI.MFilesServerApplication")
    oServerApp.Connect 2, "user", "password", "SERVERNAME", "ncacn_ip_tcp", "localhost", "7766", "DEMO VAULT", false
    Dim oVault: Set oVault = 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 = "user-" & oEmail


    oServerApp.LoginAccountOperations.AddLoginAccount oLoginAccount, "password"

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

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

    oVault.UserOperations.AddUserAccount oUserAccount

    Dim oPropVal : Set oPropVal = CreateObject("MFilesAPI.PropertyValue")

    oPropVal.PropertyDef = 1150
    oPropVal.TypedValue.SetValue MFDatatypeLookup, oUserAccount.ID
    Vault.ObjectPropertyOperations.SetProperty ObjVer, oPropVal

    oServerApp.Disconnect()

  • Try with this.

    Option Explicit
    
    Dim oServerApp: set oServerApp = CreateObject("MFilesAPI.MFilesServerApplication")
    oServerApp.Connect 2, "user", "password", "SERVERNAME", "ncacn_ip_tcp", "localhost", "7766", "DEMO VAULT", false
    Dim oVault: Set oVault = 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 = "user-" & oEmail
    
    
    oServerApp.LoginAccountOperations.AddLoginAccount oLoginAccount, "password"
    
    Dim oUserAccount: Set oUserAccount = CreateObject("MFilesAPI.UserAccount")
    
    oUserAccount.Enabled = true
    oUserAccount.InternalUser = true
    oUserAccount.LoginName = "user-" & oEmail
    
    dim userid : userid = UserOperations.AddUserAccount oUserAccount
    
    Dim oPropVal : Set oPropVal = CreateObject("MFilesAPI.PropertyValue")
    
    oPropVal.PropertyDef = 1150
    oPropVal.TypedValue.SetValue MFDatatypeLookup, userid.ID
    Vault.ObjectPropertyOperations.SetProperty ObjVer, oPropVal
    
    oServerApp.Disconnect()

Reply
  • Try with this.

    Option Explicit
    
    Dim oServerApp: set oServerApp = CreateObject("MFilesAPI.MFilesServerApplication")
    oServerApp.Connect 2, "user", "password", "SERVERNAME", "ncacn_ip_tcp", "localhost", "7766", "DEMO VAULT", false
    Dim oVault: Set oVault = 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 = "user-" & oEmail
    
    
    oServerApp.LoginAccountOperations.AddLoginAccount oLoginAccount, "password"
    
    Dim oUserAccount: Set oUserAccount = CreateObject("MFilesAPI.UserAccount")
    
    oUserAccount.Enabled = true
    oUserAccount.InternalUser = true
    oUserAccount.LoginName = "user-" & oEmail
    
    dim userid : userid = UserOperations.AddUserAccount oUserAccount
    
    Dim oPropVal : Set oPropVal = CreateObject("MFilesAPI.PropertyValue")
    
    oPropVal.PropertyDef = 1150
    oPropVal.TypedValue.SetValue MFDatatypeLookup, userid.ID
    Vault.ObjectPropertyOperations.SetProperty ObjVer, oPropVal
    
    oServerApp.Disconnect()

Children