Announcement

Collapse
No announcement yet.

Workflow that fills the date is removing the date when updates another date

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Workflow that fills the date is removing the date when updates another date

    Hello guys,

    firstly I would like to apologize for the stupid name of this topic. I had no idea what to put there to be understandable.

    Goal:
    I have a workflow that fills the date when the checkbox next to it is clicked to true.
    There are 3 checkboxes that are connected with the date next to them.
    When I click on checkbox1, date1 is set. When I click on checkbox2, date2 is set. When I click on checkbox3, date3 is set.

    Problem:
    So far it is working as expected.
    The only problem is that when I click on checkbox1, date1 is set and when I click on checkbox2, date2 is set but at the same time date1(which had value), is set to null with no reason.
    Is there anything I missed? I have more workflows like this and none of those is setting the date to null when the checkbox is "unclicked". The only difference is that those workflows are separate for each date and now for the first time I tried to combine 3 workflows into one and I am facing this weird behavior.

    Could someone please help me why it is now setting null to the dates that are already set when I am clicking on the checkbox that is connected with the other date?

    Hopefully, it is understandable.
    Cannot upload the video, please check the link https://www.veed.io/view/945b2292-d5...ue&panel=share

    Condition:
    HTML Code:
    (entity\isAttributeChanged('zaverecnaKontrolaZadostP1') && zaverecnaKontrolaZadostP1 == true) ||
    (entity\isAttributeChanged('zaverecnaKontrolaProvedenaP1') && zaverecnaKontrolaProvedenaP1 == true) ||
    (entity\isAttributeChanged('prevzate') && prevzate == true);
    Action:
    HTML Code:
    ifThen(entity\isAttributeChanged('zaverecnaKontrolaZadostP1'), datumZadostKontrolaP1 = datetime\today());
    ifThen(entity\isAttributeChanged('zaverecnaKontrolaProvedenaP1'), datumProvedenaKontrolaP1 = datetime\today());
    ifThen(entity\isAttributeChanged('prevzate'), datumPrevzatiaTechOdd = datetime\today());​
    Thanks a lot!

    edit: Usually, when I want the workflow to remove the date when the checkbox is "unclicked" I have to put there action ifThen("unclicked", date = null)
    But now it is doing this without any coding
    Attached Files
    Last edited by Jakub Grufik; 11-10-2022, 10:44 AM.

  • #2
    Hi Jakub Grufik,

    It is better to divide into three different workflows, where changing the Boolean field will set today's date.
    Or write three different formulas instead (you can experiment with the date format):
    Code:
    ifThenElse(
         checkjakub1 == true,
         jakubdate1 = datetime\today(),
         jakubdate1 = null
         );
    
    ifThenElse(
         checkjakub2 == true,
         jakubdate2 = datetime\today(),
         jakubdate2 = null
         );
    
    ifThenElse(
         checkjakub3 == true,
         jakubdate3 = datetime\today(),
         jakubdate3 = null
         );​

    The three different formulas do not conflict with each other http://g.recordit.co/WE2SPwTzJo.gif
    The three workflows should also not conflict with each other.
    Attached Files
    Last edited by victor; 11-10-2022, 11:35 AM.

    Comment


    • #3
      Hello, victor thanks a lot for the help!

      I wanted to avoid creating a separate workflow for each date because I have like 16 dates that need to be set when some checkbox is clicked. So instead of creating 16 workflows, I wanted to create just 4 more complex ones similar to the one I described above.

      My code looks correct tho so I was just wondering why it's behaving like this.

      In order to store correct dates I will have to use workflows instead of formulas. In case I would use a formula, there will be always today´s date set before saving, correct?

      Thank you man, I appreciate it!

      Comment


      • Jakub Grufik
        Jakub Grufik commented
        Editing a comment
        hey rabii, but I need to store that date historically, if I put in in the formula it will be always today´s date, or no?

      • rabii
        rabii commented
        Editing a comment
        i think you can still manage to store the date historically as the condition on the formula won't be triggered unless it is true. solution offered by victor would definitely work you can just make sure that the change is happening when a a checkbox is changed and it is equal true.

      • Jakub Grufik
        Jakub Grufik commented
        Editing a comment
        ah so I can put it into the formula and add there just another condition entity\isAttributeChanged() for each checkbox, correct? thanks a lot

    • #4
      It seems that when the entity is changed the whole code is reevaluated and seems that your action is missing some checking for the truthy of the boolean try this action instead:

      Action Code
      Code:
      ifThen(entity\isAttributeChanged('zaverecnaKontrol aZadostP1') && zaverecnaKontrolaZadostP1 == true, datumZadostKontrolaP1 = datetime\today());
      ifThen(entity\isAttributeChanged('zaverecnaKontrol aProvedenaP1') && zaverecnaKontrolaProvedenaP1 == true, datumProvedenaKontrolaP1 = datetime\today());
      ifThen(entity\isAttributeChanged('prevzate') && prevzate == true, datumPrevzatiaTechOdd = datetime\today());​​
      I think this might work.
      Cheers

      Comment


      • Jakub Grufik
        Jakub Grufik commented
        Editing a comment
        will try, thanks a lot

    • #5
      Hey rabii thanks a lot for the suggestion.

      I used this code for action and it is working exactly as before, setting the dates, but removing the previous ones.

      Code:
      ifThen(
          entity\isAttributeChanged('zaverecnaKontrolaZadostP1') && zaverecnaKontrolaZadostP1 == true,
          datumZadostKontrolaP1 = datetime\today()
          );
      
      ifThen(
          entity\isAttributeChanged('zaverecnaKontrolaProvedenaP1') && zaverecnaKontrolaProvedenaP1 == true,
          datumProvedenaKontrolaP1 = datetime\today()
          );
      
      ifThen(
          entity\isAttributeChanged('prevzate') && prevzate == true,
          datumPrevzatiaTechOdd = datetime\today()
          );​
      Seems like there is no way to achieve the goal without creating separate workflows for each date..

      Comment


      • #6
        this is what your formula code would look like, try it and disable the workflow to see the outcome:

        Code:
        ifThenElse(
        entity\isAttributeChanged('zaverecnaKontrolaZadostP1') && zaverecnaKontrolaZadostP1 == true,
        datumZadostKontrolaP1 = datetime\today(),
        
        ifThen(
        entity\isAttributeChanged('zaverecnaKontrolaZadostP1') && zaverecnaKontrolaZadostP1 == false,
        datumZadostKontrolaP1 = null
        )
        );
        
        ifThenElse(
        entity\isAttributeChanged('zaverecnaKontrolaProvedenaP1') && zaverecnaKontrolaProvedenaP1 == true,
        datumProvedenaKontrolaP1 = datetime\today(),
        
        ifThen(
        entity\isAttributeChanged('zaverecnaKontrolaProvedenaP1') && zaverecnaKontrolaProvedenaP1 == false,
        datumProvedenaKontrolaP1 = null
        )
        );
        
        ifThenElse(
        entity\isAttributeChanged('prevzate') && zaverecnaKontrolaProvedenaP1 == true,
        datumPrevzatiaTechOdd = datetime\today(),
        
        ifThen(
        ​​​​​​​entity\isAttributeChanged('prevzate') && zaverecnaKontrolaZadostP1 == false,
        datumPrevzatiaTechOdd = null
        )
        );​​

        Comment


        • #7
          victor rabii thanks a lot guys!

          It is now working as expected.
          Solved by putting the code directly into the formula of the entity as you both suggested.

          Code:
          ifThen(
              entity\isAttributeChanged('zaverecnaKontrolaZadostP1') && zaverecnaKontrolaZadostP1 == true,
              datumZadostKontrolaP1 = datetime\today()
              );
          
          ifThen(
              entity\isAttributeChanged('zaverecnaKontrolaProvedenaP1') && zaverecnaKontrolaProvedenaP1 == true,
              datumProvedenaKontrolaP1 = datetime\today()
              );
          
          ifThen(
              entity\isAttributeChanged('prevzate') && prevzate == true,
              datumPrevzatiaTechOdd = datetime\today()
              );​
          I have no idea why the workflow was not working, but it is now doing exactly what I need.
          Thanks a looot to both of you guys. You really helped me.

          Have a great rest of the day!

          Comment


          • #8
            the workflow was not working because on the action you still use an if statement and that cause the issue, actions should be only updating/creating data i guess. conditions are meant for the initial workflow trigger.

            i am glad you it is working now.

            have a good day too.

            Comment

            Working...
            X