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
  • At this point, the changes not committed yet. I suggest try make changes on the next workflow step where transition is manual. So, may be something like this in next step:

    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

    The difference between oVault and Vault is that Vault is an build-in variable that stores the connection to the vault of the current object.oVault is a variable that stores the connection to the vault made through the API.

Children
  • Of course, I understand. 

    But the script ( what I understood of it), there are two vaults involved (vault as in current vault, and oVault, a different vault).

    The script creates a user account in oVault, and then it needs to add that user account into an object.

    So this "oVault.ObjectPropertyOperations.SetProperty ObjVer, oPropVal" cannot work as ObjVer is from vault, which will not correspond to the ObjVer in oVault. So a search in oVault should be made to bring the desired ObjVer fo the command to work.

    Maybe I understood wrong the scope of the script.

  • It would work if at each step of the workflow a connection is made to the current vault to be kept in oVault. In this context, Vault and oVault will point to the same object.

  • 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)

  • 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