The M-Files Community will be updated on Tuesday, April 2, 2024 at 10:00 AM EST / 2:00 PM GMT and the update is expected to last for several hours. The site will be unavailable during this time.

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

Date Field

Hi

I have made a worflow but I am having difficulty in applying the date. So basically in my Metadata card I have inserted the date property. Now the catch is that I want the users of the workflow to only select the current date and not any other date. If I use a calculated value of Today() or set a dynamic value in my metadata card it does not work because when the flow is completed on another day the value of the date changes to the current date and not when the request was raised. In my workflow I want the user to select today's date (I don't mind if I can set it automatically as well) and then this date should not be changed. 

Thank you

Parents
  • You could use a simple script in Validation. Set conditions so that the script only sets a value if the property is empty. The value will not change with recalculation or workflow transistions.

  • Hi

    Thanks for the reply but I did not understand the solution. Could you provide an example.

    Thank you

  • Here is an old script from my archives. Have not tested lately. The comments are a bit off the date topic because it was originally developed for setting lookup values. The ideas is that Validation checks if the property value is Null. If yes then it sets todays day as default value. This happens at check in. The user won't see the default value before check in. The user may type in another value before check in, and he can change the value later on if desired.

    ' This script changes a lookup property value to a default item if left blank.
    ' Should be placed in the VALIDATION SCRIPT of corresponding property definition.
    ' v1.0.0.0 /// Joonas Saukkonen /// 9.3.2010
    ' Adapted for dates 2018.12.13 Karl Lausten
    '-------------------------------------------
    
    ' Replace the value with the ID of the default value list item
    Dim iDefaultValue : iDefaultValue = Date
    
    ' Get the data type for the Property
    Dim iDataType : iDataType = Vault.PropertyDefOperations.GetPropertyDef( PropertyValue.PropertyDef ).DataType
    
    ' If TypedValue was not set for the property
    If IsNull( PropertyValue.TypedValue ) Then
    
              ' Set the value to default
              Dim thisProperty : Set thisProperty = PropertyValue
              thisProperty.TypedValue.SetValue iDataType, iDefaultValue
    
              ' Upgrade the properties for the object
              Dim oNullVer : Set oNullVer = Vault.ObjectPropertyOperations.SetProperty( ObjVer, thisProperty )
    
    End If

  • Hi

    Thanks for the reply. I'm having trouble scripting but I just wanted to know do I need to do all this just so that the user does not input an incorrect date or change the date later on?

    Basically I want the user to input today's date and then once it has moved to the next workflow state it cannot be amended.

    Sorry for the ignorance and thanks for the support always.

  • The script will only help you ensure that the current date is placed in the property when a new object is created and checked in the first time. It will only do so if the user or some other feature has not already done so. It will not prevent anyone from changing that date later on, but it will not change automatically either once the property has a value.

    If you want to prevent anyone from changing that date later on without changing permissions on the whole object to Read Only, then you will need a more complex validation script that compares the current value with the value in version one. I do not have a script of that sort in my archive and do not have the time to develop one for you. You should be able to put one together by looking at posts where people have worked with version specific property values. I am not aware of other methods to lock down one property while keeping others open for changes on the same object.
    Well, you could change permissions on that property itself and make it read only to all users. Then you would rely on the above script to fill in the value once, and noone but administrators can change it later. If you can live with that, then go ahead.

  • Thanks but since Im not into VB scripts I do not understand how it works. My answer in red.

    ' Replace the value with the ID of the default value list item
    Dim iDefaultValue : iDefaultValue = Date (Replaced this with the ID of my date property field)

    ' Get the data type for the Property
    Dim iDataType : iDataType = Vault.PropertyDefOperations.GetPropertyDef( PropertyValue.PropertyDef ).DataType

    Replaced Property Value with Date

    ' If TypedValue was not set for the property
    If IsNull( PropertyValue.TypedValue ) Then

    ' Set the value to default
    Dim thisProperty : Set thisProperty = PropertyValue
    thisProperty.TypedValue.SetValue iDataType, iDefaultValue

    ' Upgrade the properties for the object
    Dim oNullVer : Set oNullVer = Vault.ObjectPropertyOperations.SetProperty( ObjVer, thisProperty )

    End If

  • The simpler method to prevent further changes would be via a rule configuration that sets that property to read only once it has a value.

    https://www.m-files.com/user-guide/latest/eng/metadata_card_configuration.html

    Setup your filters as needed then under Behavior add a Properties for the property in question and set 'Is Read-Only' to 'Yes'

    You would need to set the filter so that it would apply after they have set the date value, easiest way is if the date value is set as part of a workflow.

  • Wesley's suggestion sounds like a good solution for preventing changes.

    You should not have to change anything in the script. It won't work with your changes.

  • Dear Wesley

    Thanks for the reply, that solves one bit of my issue. The second bit is still unsolved. The user can input any date he likes. I want him to input only the current date.

  • After testing this, your metadatacard config should work. Set the value to dynamic = Today() like you did.

    Set 'Is Read-Only' to 'Yes' and then set 'Force Set Value' to 'No'.

    Force Set Value says whether it should overwrite any existing values with the dynamic value you configured. So if it's set to ready only with no forced value it will not be editable by the user and will auto fill with today's date and then not update that date any further.

  • Thank you. Appreciate your support, it worked

Reply Children
No Data