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?
Parents
  • 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
Reply
  • 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
Children
No Data