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

  • With this script an error occurs when trying to save the Script:

    Cliente Novo, StateCondition, 28, Expected end of statement (0x80040008)

  • dim userid : set userid = UserOperations.AddUserAccount oUserAccount on line 26

  • Sorry I had put 2 blank lines in my script (I removed Now), the error occurs on line 26 even.
    Include your last change and the same error occurred:
    Cliente Novo, StateCondition, 26, Expected end of statement (0x80040008)

  • then try:

    dim userid : set userid = UserOperations.AddUserAccount(oUserAccount)

  • I managed to save the script and when running the message occurred:

    Cliente Novo, StateCondition, 26, Variable is undefined: 'UserOperations' (0x80040008)

Reply Children
  • dim userid : set userid = oVault.UserOperations.AddUserAccount(oUserAccount)

  • New error: 

    RPCDocumentOperationsHelperPrivate.cpp, 9535, Value '80' does not exist, or is a conflict object. (0x800408E8)

    The script created the user account and it has this ID. Just failed to set the value on the property.

  • well in what vault you wanted to create the user? in oVault or in Vault?

    Where do you set the id of user? 

    Probably this line should be:

    oVault.ObjectPropertyOperations.SetProperty ObjVer, oPropVal

  • well in what vault you wanted to create the user? in oVault or in Vault?

    Resp: In oVault.

    Where do you set the id of user?

    Resp: With this part of the script:

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

    Include your last suggestion (oVault.ObjectPropertyOperations.SetProperty ObjVer, oPropVal) and different error occurred:

    (0057) (0x80040001)
    New Client, StateAction, 31, Object is locked. Try later. Object: 111-34

  • So you are trying to set on oVault, an ObjVer that it is in Vault.

    You need to search for the ObjVer from the oVault, than update the oVault.ObjectPropertyOperations.SetProperty ObjVer, oPropVal with the proper ObjVer.

  • Not really, the property is in the same Vault (oVault), correct the line by putting "oVault.ObjectPropertyOperations.SetProperty ObjVer, oPropVal" and this error occurred:

    RPCDocumentOperationsHelperPrivate.h, 2348, O objeto esta bloqueado. Tente mais tarde. Object: 111-34 (0x80040041)
    RPCDocumentOperationsHelperPrivate.cpp, 17940, O objeto esta bloqueado. Tente mais tarde. Object: 111-34 (0x80040041)
    (M-Files 21.6.10322.8)

    (0057) (0x80040001)
    (M-Files 21.6.10322.8)

  • oVault.ObjectPropertyOperations.SetProperty ObjVer, oPropVal

    The ObjVer in this statements is the current ObjVer of the document in your Vault.

    You need to find the ObjVer in oVault.

  • Radu Moca, thank you very much for your help and patience, but I couldn't write the script to find ObjVer in oVault.

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

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