Computer Reference: Content Builder



  • Category
    Content Builder
  • Title
    Initialize a read-only date field with creation date
  • Description

    In View tab, under "Editable" column click on [text].

    In Options tab mark the Readonly checkbox.
    Then in the Scripts tab in Init JS section put the code similar to this one:
    // this script fills name field with current date, but doesn't change the value on edit
    var date = new Date();
    var zero = "0";
    var yearString = (date.getFullYear()).toString().concat("/");
    var month = date.getMonth() + 1;
    var monthString = month.toString().concat("/");
    if (month10)
        { monthString = zero.concat(monthString); }
    var d = date.getDate();
    var dayString = d.toString();
    if (d 10)
        {dayString = zero.concat(dayString);}
    var stringDate1 = yearString.concat(monthString);
    var stringDate = stringDate1.concat(dayString.toString());
    if( contentbuilder._('FIELDNAME').value == "" )
        { contentbuilder._('FIELDNAME').value = stringDate ; }

    NOTE: In order for this code to work you need to replace both instances of FIELDNAME in the code with the actual name of the field you wish to fill in with current date.