Can't get == to work

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • crmclients
    Senior Member
    • Jul 2020
    • 254

    Can't get == to work

    I tried the following in both Opportunity and Lead modules, (created a Close Date field in Leads)
    • ifThen((datetime\diff(closeDate, datetime\today(), 'days')) == 1, addressStreet = 199);
    • ifThen((datetime\diff(closeDate, datetime\today(), 'days')) > 3, addressStreet = 399); // works
    • ifThen((datetime\diff(closeDate, datetime\today(), 'days')) = 4, addressStreet = 499);​
    if the date difference is 1 day then put 199 in the Street field
    if the date difference is greater than 3 put 399 instead
    =4 put 499

    It seems > or < always works but neither == nor =

    I have a field displaying the result so I know the dates work.

    Any ideas what is happening?

    Click image for larger version

Name:	image.png
Views:	226
Size:	14.1 KB
ID:	93435
  • esforim
    Active Community Member
    • Jan 2020
    • 2204

    #2
    Look good to me, I haven't tried it yet.

    I recommend you do a Print Outline of this:

    datetime\diff(closeDate, datetime\today(), 'days'

    See if you can get it to be "1" in the sandbox formula, then try the formula again. I use == as well.

    Comment

    • crmclients
      Senior Member
      • Jul 2020
      • 254

      #3
      sorry im not sure I understand what you mean by Print Outline
      the formula does return a number if that is what your are asking - i set up the pidx field to capture the results - i just turned it off to ensure nothing was interfering
      besides, it works for > or < just not for Equals anything

      do you think it has something to do with the field types?

      Click image for larger version  Name:	image.png Views:	0 Size:	24.2 KB ID:	93455​​
      Attached Files
      Last edited by crmclients; 06-08-2023, 06:15 AM.

      Comment

      • esforim
        Active Community Member
        • Jan 2020
        • 2204

        #4
        Field type does matter, with varchar I think you have to enclose it as '1' for example, with number interger it just a simple 1. I'm writing this on memory.

        Create a test record where you can get the two date to be equal to =1 and test your formula in the Sandbox.

        Here what I mean
        Click image for larger version  Name:	image.png Views:	0 Size:	6.9 KB ID:	93464​ I use this to do live test before I copy/paste it to my formula.

        Click image for larger version  Name:	image.png Views:	0 Size:	14.5 KB ID:	93461


        Click image for larger version  Name:	image.png Views:	0 Size:	7.5 KB ID:	93462
        Click image for larger version  Name:	image.png Views:	0 Size:	7.3 KB ID:	93463

        Comment

        • lazovic
          Super Moderator
          • Jan 2022
          • 809

          #5
          Hi crmclients,

          I will try to explain to you the difference between the = and == operators:

          = – assignment,
          ​== – comparison equals.

          In your case, it is best to use the following formula:
          Code:
          ifThen(
          datetime\diff(closeDate, datetime\today(), 'days') == 1,
          addressStreet = 199
          );
          
          ifThen(
          datetime\diff(closeDate, datetime\today(), 'days') > 3,
          addressStreet = 399
          );
          
          ifThen(
          datetime\diff(closeDate, datetime\today(), 'days') == 4,
          addressStreet = 499
          );​
          Also, remember the full syntax of the formula:

          datetime\diff(VALUE_1, VALUE_2, INTERVAL_TYPE)



          Note that the result will be negative if VALUE_1 < VALUE_2.

          That is, in your case, if the datetime\today() value is greater than the closeDate value, the result will be in the format -1, -2, -3, and so on.

          As esforim correctly pointed out, your best bet is to test this formula in the Formula Sandbox in the following format:
          Code:
          output\printLine(datetime\diff(closeDate, datetime\today(), 'days'));
          output\printLine(datetime\diff(datetime\today(), closeDate, 'days'));

          Thus, you will be able to understand how many days and in what cases will be calculated correctly.
          Last edited by lazovic; 06-08-2023, 11:48 AM.

          Comment

          • crmclients
            Senior Member
            • Jul 2020
            • 254

            #6
            It looks the same as my original post except you are saying quotes are not needed?

            this is how i confirm output below, i put in in a field so I have a record, in this case Pidx, is this what your printline is doing?

            you can see, it is blank for EQUALS = which is the issue of what not working, quotes or no quotes - i copied your code exacting and nothing appeared but the math is working

            ifThen(
            datetime\diff(closeDate, datetime\today(), 'days') == 4,
            addressStreet = 499
            );
            pidx = (datetime\diff(closeDate, datetime\today(), 'days'))​


            Click image for larger version

Name:	image.png
Views:	150
Size:	19.1 KB
ID:	93507​​
            if you think i still need to do the sandbox ill have to try that at a later time
            Attached Files

            Comment

            • crmclients
              Senior Member
              • Jul 2020
              • 254

              #7
              esforim lazovic all this did was confirm the math which is not the issue, there appears to be a problem with the execution for == with or without quotes




              Click image for larger version

Name:	image.png
Views:	170
Size:	17.2 KB
ID:	93514

              Comment

              • esforim
                Active Community Member
                • Jan 2020
                • 2204

                #8
                I don't get it, your Pidx is showing 1 2 3 4 5 6 as result. Not sure which one is your "Mee" one is but it showing as '657' as the result, this mean your formula is wrong.

                You have to test and use the record it so your output\printline will as "4" then you can write the next step to your formula.

                If you manage to calculate the PIDx already, why not just use PidX?

                For example:

                if {pidX==1, addressStreet = 399}


                Click image for larger version

Name:	image.png
Views:	161
Size:	1.2 KB
ID:	93526
                Click image for larger version

Name:	image.png
Views:	147
Size:	12.0 KB
ID:	93527

                Comment

                • lazovic
                  Super Moderator
                  • Jan 2022
                  • 809

                  #9
                  crmclients,

                  It is better not to put extra brackets in the formula script, so I removed them from my example. But even my example was not entirely correct.

                  I dare to believe that the Address Street field in your EspoCRM instance is a Varchar field, that is, a text field. And in the formula, we assign it a purely numeric value, like a field with type Integer or Float, when we do not use the upper brackets. Field types are very important when working with a formula; in this case, you cannot assign a numeric value to a text field.

                  Given all of the above, I can confirm, after checking everything on my EspoCRM instance, that the following formula will work for you:​
                  Code:
                  ifThen(
                  datetime\diff(closeDate, datetime\today(), 'days') == 1,
                  addressStreet = '199'
                  );
                  
                  ifThen(
                  datetime\diff(closeDate, datetime\today(), 'days') > 3,
                  addressStreet = '399'
                  );
                  
                  ifThen(
                  datetime\diff(closeDate, datetime\today(), 'days') == 4,
                  addressStreet = '499'
                  );

                  Comment

                  Working...