locked
Bolding the field with the highest date value? RRS feed

  • Question

  • Hi,

    I have two date-fields in a form, and would like to mark the field with the highest date bold.

    I tried this script but nothing hppened. I think it all depending how I formulate the script regarding which value is the highest.

      if (date1.DataValue >date2)
    Did not work.

    Script:

    var Garanti1 = crmForm.all.new_garantiutgr ;
    var Garanti2 = crmForm.all.new_garantiutgr2 ;


    if (Garanti1.DataValue != null) {
      if (Garanti1.DataValue >Garanti2)
         {
      var field = crmForm.all.new_garantiutgr;
      field.style.fontWeight = 'bold';
      field.style.fontSize = '12px';
          }
    }

    if (Garanti2.DataValue != null) {
      if (Garanti2.DataValue >Garanti1)
         {
      var field = crmForm.all.new_garantiutgr2;
      field.style.fontWeight = 'bold';
      field.style.fontSize = '12px';
          }
    }

    would appriciate som assistens with this.

    Thank you in advance

    / Marinfloc

    Thursday, June 17, 2010 7:09 AM

Answers

  • Hi,

    you have to change it like as below

    if (Expire1.DataValue != null) {
     if (Expire1.DataValue > Expire2.DataValue)
     {
     crmForm.all.new_total_utgar.DataValue = Expire1.DataValue;
     }
    }

    var Expire1 = crmForm.all.new_garantiutgr;
    var Expire2 = crmForm.all.new_garantiutgr2;

    if (Expire1.DataValue != null) {
     if (Expire2.DataValue > Expire1.DataValue)
     {
     crmForm.all.new_total_utgar.DataValue = Expire2.DataValue;
     }
    }


    Mahain
    Monday, June 21, 2010 12:58 PM
    Moderator

All replies

  • You should use

    Garanti2.DataValue >Garanti1.DataValue

    instead of

    Garanti2.DataValue >Garanti1


    Truth is opened the prepared mind

    My blog (english)
    Мой блог (русскоязычный)
    Thursday, June 17, 2010 7:15 AM
    Moderator
  • Hi Ma rinfloc,

     I hope next code will help you:

    var Garanti1 = crmForm.all.new_garantiutgr;
    var Garanti2 = crmForm.all.new_garantiutgr2;

    if (Garanti1.DataValue != null) {
      if (Garanti1.DataValue >Garanti2.DataValue)
         {
            Garanti1.style.fontWeight = 'bold';
            Garanti1.style.fontSize = '12px';
         }
    }

    if (Garanti2.DataValue != null) {
      if (Garanti2.DataValue > Garanti1.DataValue)
         {
           Garanti2.style.fontWeight = 'bold';
           Garanti2.style.fontSize = '12px';
         }
    }

    Thursday, June 17, 2010 8:21 AM
  • also, you can use next example, this example show all possible options for the font:

     

    var Garanti1 = crmForm.all.new_garantiutgr;
    var Garanti2 = crmForm.all.new_garantiutgr2;
    
    if (Garanti1.DataValue != null) {
     if (Garanti1.DataValue >Garanti2.DataValue)
      {
      Garanti1.style.font = 'italic small-caps bold 12px arial,sans-serif';
      }
    }
    
    if (Garanti2.DataValue != null) {
     if (Garanti2.DataValue > Garanti1.DataValue)
      {
      Garanti2.style.font = 'italic small-caps bold 12px arial,sans-serif';
      }
    }

     

    Thursday, June 17, 2010 8:35 AM
  • Hi,

    I have tried your suggestions, but nothing is happening.

    I dont receive any error and none of the date-field is changing?

    Any suggestion?

    / Marindloc

    Thursday, June 17, 2010 11:51 AM
  • Hi,

     Yes, I have other suggestion. This code will help you:

    var Garanti1 = crmForm.all.new_garantiutgr;
    var Garanti2 = crmForm.all.new_garantiutgr2;
    
    if (Garanti1.DataValue != null) {
     if (Garanti1.DataValue >Garanti2.DataValue)
     {
     Garanti1.document.getElementById('DateInput').style.font = 'italic small-caps bold 12px arial,sans-serif';
     }
    }
    
    if (Garanti2.DataValue != null) {
     if (Garanti2.DataValue > Garanti1.DataValue)
     {
     Garanti2.document.getElementById('DateInput').style.font = 'italic small-caps bold 12px arial,sans-serif';
     }
    }
    

    Thursday, June 17, 2010 12:22 PM
  • Hí,

    Just tried the new code.

    Nothing...

    I also tried the following to just se if a date-field could be changed.

    var Garanti1 = crmForm.all.new_garantiutgr1;

     Garanti1.document.getElementById('DateInput').style.font = 'italic small-caps bold 12px arial,sans-serif';

    And nothing happened.

    So maybe its not possible to change style to a date-field?

    I hope I am wrong about this...

    Friday, June 18, 2010 9:19 AM
  • Hi ,

    I don't see how. I am assured this code is true!

    1. Settings->Customization->Customize Entities

    2. Select Entity

    3. Forms and Views -> Form -> Form properties -> OnLoad -> Edit

    4.  Check Event i s enabled -> put code

    5. Save and Close

    6. Actions -> Publish

     

    And the results turned out brilliant, like below:

     

    Friday, June 18, 2010 9:55 AM
  • Hi,

    My date-field is without time, could that be the problem?

    I dont have any use for the time, just the date.

     

    And, I also dont have the date format 6/8/2010. I have the format 2010-08-06.

    If it matter?

     

    / Marinfloc

    Friday, June 18, 2010 10:51 AM
  • No,

    It will also work for dateonly


    Mahain
    Friday, June 18, 2010 11:05 AM
    Moderator
  • Hi,

    It is really weird, i tested the code in another entity and it worked, but in the entity were I need the code it doesn’t work?

    In the OnLoad code there already is a code, i have not created it so I don’t know how it works. Is it a possibility that the already existing code somehow disturbs the new code?

    the existing code is:

    var CRM_FORM_TYPE_CREATE = 1;
    var CRM_FORM_TYPE_UPDATE = 2;
    var cRootFolder = "\\\\XXXXX\\gemold\\object\\maps\\";

    function PadDigits(n, totalDigits)
    {
            n = n.toString();
            var pd = '';
            if (totalDigits > n.length)
            {
                for (i=0; i < (totalDigits-n.length); i++)
                {
                    pd += '0';
                }
            }
            return pd + n.toString();
    }

    switch (crmForm.FormType)
    {
        case CRM_FORM_TYPE_CREATE:
            crmForm.all.IFRAME_DOCUMENT.style.display = 'none';

            break;

       case CRM_FORM_TYPE_UPDATE:
            if (crmForm.all.new_name.DataValue != null)
            {
                var lookupAnlType = new Array;
                lookupAnlType = crmForm.all.new_testproduktid.DataValue
                var AnlType = lookupAnlType[0].name;
                var AnlName = PadDigits(crmForm.all.new_name.DataValue,4);
                // var FolderPath = AnlType + "\\" + AnlName;
                var FolderPath = AnlName;

                crmForm.all.IFRAME_DOCUMENT.src
             = "http://XXXX/simpledocumentmanager/default.aspx?RootFolder=" + cRootFolder + "&Folder=" + FolderPath;
             }
            else
           {
              crmForm.all.IFRAME_DOCUMENT.style.display = 'none';
           }

         break;
    }

     

    I know wht the code does, but is there anything is this code that disturbs my requested code?

    / Marinfloc

    Monday, June 21, 2010 9:13 AM
  • Hi,

    I will suggest you to debug it.

    refer below link for more information on debugging

    http://blogs.msdn.com/b/crm/archive/2009/04/06/part-2-ie-8-developer-tools-and-crm-4-client-side-debugging.aspx

    Hope it will help you !!!


    Mahain
    Monday, June 21, 2010 11:00 AM
    Moderator
  • Hi,

    I will try to debug it, have never tried the developer tools but the link you gave seems good.

    Unitl I have fixed this maybe some can help me with a plan B.

    Instead of marking the correct date, sum the correct date into a other field?

    I have tried the following code, without any success...


    var Expire1 = crmForm.all.new_garantiutgr;
    var Expire2 = crmForm.all.new_garantiutgr2;

    if (Expire1.DataValue != null) {
     if (Expire1.DataValue > Expire2.DataValue)
     {
     crmForm.all.new_total_utgar.DataValue = Expire1;
     }
    }

    var Expire1 = crmForm.all.new_garantiutgr;
    var Expire2 = crmForm.all.new_garantiutgr2;

    if (Expire1.DataValue != null) {
     if (Expire2.DataValue > Expire1.DataValue)
     {
     crmForm.all.new_total_utgar.DataValue = Expire2;
     }
    }

    crmForm.all.new_total_utgar.ForceSubmit = true;

     

    Thank you.

     

    / Marinfloc

    Monday, June 21, 2010 12:21 PM
  • Hi,

    you have to change it like as below

    if (Expire1.DataValue != null) {
     if (Expire1.DataValue > Expire2.DataValue)
     {
     crmForm.all.new_total_utgar.DataValue = Expire1.DataValue;
     }
    }

    var Expire1 = crmForm.all.new_garantiutgr;
    var Expire2 = crmForm.all.new_garantiutgr2;

    if (Expire1.DataValue != null) {
     if (Expire2.DataValue > Expire1.DataValue)
     {
     crmForm.all.new_total_utgar.DataValue = Expire2.DataValue;
     }
    }


    Mahain
    Monday, June 21, 2010 12:58 PM
    Moderator
  • Hi,

    It worked perfectly!

    Thank you!!

    Monday, June 21, 2010 1:38 PM