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

A little VB Script help please?

Former Member
Former Member
I have property definitions for FirstName, Surname, and FullName.
I need the user to be able to enter the FullName in a single field, and to automatically calculate the FirstName and Surname.
I can use the automatic value 'Simple concatenating of properties' to achieve the reverse result, but presume I need to use Calculated Value(VBScript) to separate the FirstName and Surname.
I could do it easily in EXCEL but I'm not a programmer and don't know how to do it with VBScript. ???
I wonder if somebody would be kind enough to give me the code for this?
  • Former Member
    Former Member
    Can you specify in more detail how the FullName is entered. Is it e.g.


    • Firstname, Lastname

    • Firstname Lastname

    • Firstname MiddleName Lastname

    • Lastname, Firstname

    • Lastname Firstname

    • Lastname MiddleName Firstname



    Or something else? Then, based on your specification it is easier to give you the exact code that works as expected.

    Also, have you consideted working the other way around? E.g. having separate property definitions for the FirstName and LastName? Then, it is very easy to use the simple concatenation feature to concatenate the FullName property.

    Samppa

    P.S. Also all M-Files solution providers and M-Files consultants would be more than happy to help you with your scripting needs (but this is usually for a fee)
  • Former Member
    Former Member

    Can you specify in more detail how the FullName is entered. Is it e.g.


    • Firstname, Lastname

    • Firstname Lastname

    • Firstname MiddleName Lastname

    • Lastname, Firstname

    • Lastname Firstname

    • Lastname MiddleName Firstname



    Or something else? Then, based on your specification it is easier to give you the exact code that works as expected.
    We'll just do Firstname, Lastname.


    Also, have you consideted working the other way around? E.g. having separate property definitions for the FirstName and LastName? Then, it is very easy to use the simple concatenation feature to concatenate the FullName property.
    Yes, I tried that. However I need the Full Name to be set as the name for the record so that it appears in the parent record. (The parent record is class = Phone Call and the child record is class = Client) If I use the simple concatenate approach I muse choose Firstname or Lastname as the object name, but I really need the Full Name to be the object name. The aim is for the user, while adding a new phone call, to be able to add a value (e.g Client = Andy Andrews). However, we also need to retain separate Firstname and Lastname to allow for future data export.


    P.S. Also all M-Files solution providers and M-Files consultants would be more than happy to help you with your scripting needs (but this is usually for a fee)
    I understand that, and Infomatic have been extremely helpful. However, we are a small, volunteer-run, non-profit association and it is already stretching our budget to purchase M-Files. I am now retired from a career in IT (but never acquired programming skills) and have taken on the project of evaluating prospective applications (M-Files wins hands down), making the selection, and doing the implementation. I have allowed plenty of time to work my way through the learning curve.

    I realise that there may be a better way to do this that I am missing because I am very much at the beginning of a big learning curve. Always open to suggestions as to the best approach.

    Thanks for your help so far.
  • Former Member
    Former Member

    We'll just do Firstname, Lastname.


    For that, you can do e.g. the following: Create a new property definition called FirstName and add code (Property Definition properties -- Automatic Value tab -- Calculated Value) to separate the first part of the name to that as the value:

    Option Explicit

    ' Get First Name from FullName
    ' 0 equals to Name or Title property definition
    Dim szFullName
    Dim szFirstName
    Dim iCommaPosition
    szFullName = PropertyValues.SearchForProperty(0).TypedValue.DisplayValue
    iCommaPosition = InStr(szFullName, ",") - 1
    szFirstName = Left(szFullName,iCommaPosition)

    ' Set result.
    Output = szFirstName


    The code is just a sample -- it needs some error checking etc. for production use. By modifying the code sample you can do the same for the LastName.


    ...I need the Full Name to be set as the name for the record so that it appears in the parent record. (The parent record is class = Phone Call and the child record is class = Client) If I use the simple concatenate approach I muse choose Firstname or Lastname as the object name, but I really need the Full Name to be the object name. The aim is for the user, while adding a new phone call, to be able to add a value (e.g Client = Andy Andrews). However, we also need to retain separate Firstname and Lastname to allow for future data export.


    You could probably do the same setup with 3 properties:

    • FirstName
    • LastName
    • FullName

    Then, FullName would be set to be an Automatic Value that concatenates the FirstName and LastName. Then, you can set the FullName to be the name of the object (in Class properties, select the property you want to set as name and press Set As Name button). This would eliminate the need for vbscript code, since you could use the simple concatenation option to populate the FullName property.

    Samppa
  • Former Member
    Former Member
    You could probably do the same setup with 3 properties:

    • FirstName
    • LastName
    • FullName

    Then, FullName would be set to be an Automatic Value that concatenates the FirstName and LastName. Then, you can set the FullName to be the name of the object (in Class properties, select the property you want to set as name and press Set As Name button). This would eliminate the need for vbscript code, since you could use the simple concatenation option to populate the FullName property.

    Thanks for your guidance on this. I tried the VBScript code but it didn't work and I didn't have the knowledge to debug it myself.
    I had explored the simple concatenation approach but hadn't realised how accommodating it was and wrongly assumed some limitations that don't exist. It is simple and works well.

    The only minor downside is that, if FullName is automatically calculated, and I use it as the class name for 'Client', and the user needs to create a new Client from within Phone Call it doesn't carry over the name they type in and they have to re-type FirstName and LastName. It's no big deal, but that is why I was experimenting with making FisrstName and LastName the calculated fields. Obviously wouldn't be an issue for clients who are already in the system.

    Thanks again!
  • Former Member
    Former Member
    What kind of an error message did you get when you run the code? I tested it quickly on my test system, and it seemed to work at least in simple cases.

    Samppa
  • Former Member
    Former Member
    I started this again from scratch and got the same error (below) but doesn't mean much to me.
    Please note that I am doing this remotely. Could that be an issue?

    PropertyField_ComboBox.cpp, 276, Creating a new object failed. (0x80040419)
    PropertyFieldGroup.cpp, 2999, Creating a new object failed. (0x80040419)
    PropertyFieldGroup.cpp, 4362, Creating a new object failed. (0x80040419)
    ValueListItemUIHelper.cpp, 298, Creating a new object failed. (0x80040419)
    PropertySheetObject.cpp, 6623, Creating a new object failed. (0x80040419)
    PropertySheetObject.cpp, 6623, Calculation of the automatic value of the property 'FirstName' failed. (0x80040107)
    PropertySheetObject.cpp, 3545, Calculation of the automatic value of the property 'FirstName' failed. (0x80040107)
    CoVaultMountingDocumentOperations.cpp, 380, Calculation of the automatic value of the property 'FirstName' failed. (0x80040107)
    DocumentCache.cpp, 3882, Calculation of the automatic value of the property 'FirstName' failed. (0x80040107)
    DocumentCache.cpp, 3942, Calculation of the automatic value of the property 'FirstName' failed. (0x80040107)
    DocumentCache.cpp, 4078, Calculation of the automatic value of the property 'FirstName' failed. (0x80040107)
    RPCDocumentOperations.cpp, 117, Calculation of the automatic value of the property 'FirstName' failed. (0x80040107)
    RPCDocumentOperationsHelper.cpp, 1311, Calculation of the automatic value of the property 'FirstName' failed. (0x80040107)
    RPCDocumentOperationsHelper.cpp, 23766, Calculation of the automatic value of the property 'FirstName' failed. (0x80040107)
    RecalculateProperties.cpp, 464, Calculation of the automatic value of the property 'FirstName' failed. (0x80040107)
    RecalculateProperties.cpp, 464, Script execution failed. ((116-2-1)) (0x800408BB)
    RecalculateProperties.cpp, 1331, Script execution failed. ((116-2-1)) (0x800408BB)
    RecalculateProperties.cpp, 1021, Script execution failed. ((116-2-1)) (0x800408BB)
    RecalculateProperties.cpp, 1393, Script execution failed. ((116-2-1)) (0x800408BB)
    RecalculateProperties.cpp, 1134, Script execution failed. ((116-2-1)) (0x800408BB)
    VaultObjScriptSessionTemplates.cpp, 256, Script execution failed. ((116-2-1)) (0x800408BB)
    VaultObjScriptSessionTemplates.cpp, 256, Type mismatch: 'OOption'
    Source: Microsoft VBScript runtime error
    Line: 1
    Error: 0x800a000d (0x800A000D)
    VaultObjScriptSessionTemplates.cpp, 325, Type mismatch: 'OOption'
    Source: Microsoft VBScript runtime error
    Line: 1
    Error: 0x800a000d (0x800A000D)
    CoActiveScriptSite.cpp, 805, Type mismatch: 'OOption'
    Source: Microsoft VBScript runtime error
    Line: 1
    Error: 0x800a000d (0x800A000D)
    CoActiveScriptSite.cpp, 649, Type mismatch: 'OOption'
    Source: Microsoft VBScript runtime error
    Line: 1
    Error: 0x800a000d (0x800A000D)
    (M-Files 8.0.2910.10)
  • Former Member
    Former Member
    CoActiveScriptSite.cpp, 649, Type mismatch: 'OOption'
    Source: Microsoft VBScript runtime error
    Line: 1
    Error: 0x800a000d (0x800A000D)
    (M-Files 8.0.2910.10)


    Actually if you scroll the error message all they way down, this should be pretty easy to solve. The error message says that there is VBScript runtime error on line 1 of your code. Detailed error is "Type mismatch: 'OOption'".

    My guess would be that you have typed in the first line incorrectly. Make sure you have the first code line to state exactly "Option Explicit", not e.g. "OOption Explicit".

    Samppa
  • Former Member
    Former Member
    Careless of me, but that wasn't actually the problem, just to typo while I was replicating it.
    I have corrected that error and now get the same message as I got originally

    PropertyField_ComboBox.cpp, 276, Creating a new object failed. (0x80040419)
    PropertyFieldGroup.cpp, 2999, Creating a new object failed. (0x80040419)
    PropertyFieldGroup.cpp, 4362, Creating a new object failed. (0x80040419)
    ValueListItemUIHelper.cpp, 298, Creating a new object failed. (0x80040419)
    PropertySheetObject.cpp, 6623, Creating a new object failed. (0x80040419)
    PropertySheetObject.cpp, 6623, Calculation of the automatic value of the property 'FirstName' failed. (0x80040107)
    PropertySheetObject.cpp, 3545, Calculation of the automatic value of the property 'FirstName' failed. (0x80040107)
    CoVaultMountingDocumentOperations.cpp, 380, Calculation of the automatic value of the property 'FirstName' failed. (0x80040107)
    DocumentCache.cpp, 3882, Calculation of the automatic value of the property 'FirstName' failed. (0x80040107)
    DocumentCache.cpp, 3942, Calculation of the automatic value of the property 'FirstName' failed. (0x80040107)
    DocumentCache.cpp, 4078, Calculation of the automatic value of the property 'FirstName' failed. (0x80040107)
    RPCDocumentOperations.cpp, 117, Calculation of the automatic value of the property 'FirstName' failed. (0x80040107)
    RPCDocumentOperationsHelper.cpp, 1311, Calculation of the automatic value of the property 'FirstName' failed. (0x80040107)
    RPCDocumentOperationsHelper.cpp, 23766, Calculation of the automatic value of the property 'FirstName' failed. (0x80040107)
    RecalculateProperties.cpp, 464, Calculation of the automatic value of the property 'FirstName' failed. (0x80040107)
    RecalculateProperties.cpp, 464, Script execution failed. ((116-3-1)) (0x800408BB)
    RecalculateProperties.cpp, 1331, Script execution failed. ((116-3-1)) (0x800408BB)
    RecalculateProperties.cpp, 1021, Script execution failed. ((116-3-1)) (0x800408BB)
    RecalculateProperties.cpp, 1393, Script execution failed. ((116-3-1)) (0x800408BB)
    RecalculateProperties.cpp, 1134, Script execution failed. ((116-3-1)) (0x800408BB)
    VaultObjScriptSessionTemplates.cpp, 256, Script execution failed. ((116-3-1)) (0x800408BB)
    VaultObjScriptSessionTemplates.cpp, 256, Not found.

    CoPropertyValues.cpp, 283, Not found. (0x8004000B)
    (M-Files 8.0.2910.10)

    (0010)
    Source: M-Files 8.0.2910.10
    Line: 8
    Error: 0x80040001 (0x80040001)
    VaultObjScriptSessionTemplates.cpp, 325, Not found.

    CoPropertyValues.cpp, 283, Not found. (0x8004000B)
    (M-Files 8.0.2910.10)

    (0010)
    Source: M-Files 8.0.2910.10
    Line: 8
    Error: 0x80040001 (0x80040001)
    CoActiveScriptSite.cpp, 805, Not found.

    CoPropertyValues.cpp, 283, Not found. (0x8004000B)
    (M-Files 8.0.2910.10)

    (0010)
    Source: M-Files 8.0.2910.10
    Line: 8
    Error: 0x80040001 (0x80040001)
    CoActiveScriptSite.cpp, 649, Not found.

    CoPropertyValues.cpp, 283, Not found. (0x8004000B)
    (M-Files 8.0.2910.10)

    (0010)
    Source: M-Files 8.0.2910.10
    Line: 8
    Error: 0x80040001 (0x80040001)
    (M-Files 8.0.2910.10)
  • Former Member
    Former Member
    Do you use the property with ID 0 in your object type as the Full Name? If not, you have to change that on the line 8 to match the property ID you are using.

    Samppa
  • Former Member
    Former Member
    you have to change that on the line 8 to match the property ID you are using.
    Aha! Thanks for that. Works perfectly now. I replaced the Comma Postion with Space Position so that the FullName presents normally. I guess it will work fine so long as we don't have to deal with someone putting in two spaces accidentally.

    Thanks for your help.