locked
How to set RequiredInForms to false in BCS RRS feed

  • Question

  • Hi,

    In BCS, how to set the RequiredInForms to false for Date Time data type?

    I have currently a datetime value which is shown as a required field, but i would want it to be non-mandatory field.

    This is the code i have used, but it doesnt set the field to non-mandatory

    [CODE]

    <TypeDescriptor Name="MyCustomDate" TypeName="System.DateTime">
    <Properties>
        <Property Name="RequiredInForms" Type="System.Boolean">false</Property>
    </Properties>
    </TypeDescriptor>

    [/CODE]

    Thank you.

    Tuesday, August 9, 2011 1:15 PM

Answers

  • To expound on what Dmitry said here, resolving this issue has to happen on several fronts. 

    First, you need to define the underlying datatype for the DateTime property to a nullable DateTime:

    [CODE]

            [DataMember]
            public DateTime? StartDate { get; set; }

    [/CODE]

    Second, when you define your TypeDescriptor DateTime field, you need to make it nullable AND not required:

    [CODE]

    <TypeDescriptor Name="StartDate" TypeName="System.Nullable`1[[System.DateTime]]" LobName="StartDate" IsCollection="false">
    <Properties>
    <Property Name="RequiredInForms" Type="System.Boolean">false</Property>
    </Properties>
    <Interpretation>
    <NormalizeDateTime LobDateTimeMode="Local" />
    </Interpretation>
    </TypeDescriptor>

    [/CODE]

    Next,  when you get the data, you need to ensure that it is a nullable DateTime value:

    [CODE]

    StartDate = reader.GetNullable<DateTime>("Start_Date")

    [/CODE]

    Finally, when you pull the data from your source, you need to check the null value before you assign it to the TypeDescriptor:

    [CODE]

    // code from ReadItem method, after the specific record is found

    if (opReporting.StartDate == null)
    {
    opReporting.StartDate = (Nullable<DateTime>)null;
    }
    [/CODE]

    It should also go without saying that you need to make sure that the SQL update script on the backend processes a null value.

    Perhaps Dmitry's answer was enough help for some of us, but I needed several other things to happen before I could implement this requirement.

    • Proposed as answer by Keith Hamilton Thursday, June 14, 2012 1:31 PM
    • Marked as answer by Venkatzeus Wednesday, January 7, 2015 1:02 PM
    Thursday, June 14, 2012 1:31 PM
  • Hi,

    It's not possible to do for DateTime type. Because the nullability of a type descriptors’ underlying data type determines whether the field is required or not in an auto-generated list form tied into an external list. Because the System.DateTime type is not nullable in .NET, the type descriptors of type DateTime fields (and others like int, double) are always mandatory.

    To have this field as non-mandatory will be possible if you change the data type as follows:

    <TypeDescriptor Name="MyCustomDate" TypeName="System.Nullable`1[[System.DateTime]]">
    


    Dmitry

    Lightning Tools LogoLightning Tools Check out our SharePoint tools and web parts
    • Marked as answer by Venkatzeus Wednesday, August 10, 2011 2:22 PM
    Wednesday, August 10, 2011 10:44 AM

All replies

  • Hi,

    On what form would you want to make this field invisible?


    Dmitry

    Lightning Tools LogoLightning Tools Check out our SharePoint tools and web parts
    Tuesday, August 9, 2011 9:20 PM
  • HI,

    Thank you very much for the reply.

    I would like it to be non-mandatory and not invisible.

    On the Edit Item, i want this field to be non-mandatory.

    Wednesday, August 10, 2011 4:29 AM
  • make  <Property required=false></Property>


    Thanks yogesh
    Wednesday, August 10, 2011 9:48 AM
  • Hi,

    It's not possible to do for DateTime type. Because the nullability of a type descriptors’ underlying data type determines whether the field is required or not in an auto-generated list form tied into an external list. Because the System.DateTime type is not nullable in .NET, the type descriptors of type DateTime fields (and others like int, double) are always mandatory.

    To have this field as non-mandatory will be possible if you change the data type as follows:

    <TypeDescriptor Name="MyCustomDate" TypeName="System.Nullable`1[[System.DateTime]]">
    


    Dmitry

    Lightning Tools LogoLightning Tools Check out our SharePoint tools and web parts
    • Marked as answer by Venkatzeus Wednesday, August 10, 2011 2:22 PM
    Wednesday, August 10, 2011 10:44 AM
  • HI,

    Thank you very much for the reply.

    [CODE]

    <TypeDescriptor Name="MyCustomDate" TypeName="System.Nullable`1[[System.DateTime]]">
    

    [/CODE]

    So, is the only code required. Requiredfield property is not needed,rite..

    Wednesday, August 10, 2011 11:34 AM
  • Yes, it will be a non-mandatory field by default. If you wish to set it as mandatory you should add this property then:

    <Properties>
      <Property Name="RequiredInForms" Type="System.Boolean">true</Property>
    </Properties>
    



    Dmitry

    Lightning Tools LogoLightning Tools Check out our SharePoint tools and web parts
    Wednesday, August 10, 2011 11:50 AM
  • HI,

    Thank you very much for the reply.

    Wednesday, August 10, 2011 2:22 PM
  • To expound on what Dmitry said here, resolving this issue has to happen on several fronts. 

    First, you need to define the underlying datatype for the DateTime property to a nullable DateTime:

    [CODE]

            [DataMember]
            public DateTime? StartDate { get; set; }

    [/CODE]

    Second, when you define your TypeDescriptor DateTime field, you need to make it nullable AND not required:

    [CODE]

    <TypeDescriptor Name="StartDate" TypeName="System.Nullable`1[[System.DateTime]]" LobName="StartDate" IsCollection="false">
    <Properties>
    <Property Name="RequiredInForms" Type="System.Boolean">false</Property>
    </Properties>
    <Interpretation>
    <NormalizeDateTime LobDateTimeMode="Local" />
    </Interpretation>
    </TypeDescriptor>

    [/CODE]

    Next,  when you get the data, you need to ensure that it is a nullable DateTime value:

    [CODE]

    StartDate = reader.GetNullable<DateTime>("Start_Date")

    [/CODE]

    Finally, when you pull the data from your source, you need to check the null value before you assign it to the TypeDescriptor:

    [CODE]

    // code from ReadItem method, after the specific record is found

    if (opReporting.StartDate == null)
    {
    opReporting.StartDate = (Nullable<DateTime>)null;
    }
    [/CODE]

    It should also go without saying that you need to make sure that the SQL update script on the backend processes a null value.

    Perhaps Dmitry's answer was enough help for some of us, but I needed several other things to happen before I could implement this requirement.

    • Proposed as answer by Keith Hamilton Thursday, June 14, 2012 1:31 PM
    • Marked as answer by Venkatzeus Wednesday, January 7, 2015 1:02 PM
    Thursday, June 14, 2012 1:31 PM
  • Thank you Keith for breaking it down like that, it worked perfectly for me after pulling my hair out since yesterday.
    Wednesday, December 31, 2014 12:03 PM