0

How to update automatically "Trigger after update" option of a field?

Hello everyone,

Is it possible to automatically update (for a period of time that we define, for example every day) the "Trigger after update" option of a field?

Here is a simplified example of what I would like to do. Let's say I create a date field "SendingMailDate", another "ResponseMailDate", and a selection field "Selection Field" containing three values: "In process", "Do a reminder" and "Email answered".

Here is the condition I want to set up: if the difference between the date of sending and the current date (today()) is less than 15 days, then "Selection Field" = "In process". On the other hand, if this difference is greater than or equal to 15, then "Selection Field" = "Do a reminder".

Here is the code I enter in the "Trigger after update" part of my "SendingMailDate" field:

if days(SendingMailDate, today()) < 15 then

   'Selection Field' := 1  //In process

else 

  'Selection Field' := 2  //Do a reminder

end

(if there is a slight clerical error in the code, it's not important, it's for the idea here)

However, if I fill in my "SendingMailDate" field on the same day as the sending, the difference will remain the same despite the days that will pass since the field must be modified by hand to create the trigger.

So my question: is it possible to make the update happen by itself (or via a button to press, or as soon as the table is opened) since it depends on the time difference with the today() function?

Thanks in advance for your help!

Romain

PS: of course this is an example, in my personal case, things are slightly more complicated and I really need the code to be in the "Trigger after update" box (several fields in my table can and will modify the same selection field and it is easier to separate all the conditions in each field concerned)

9 replies

null
    • Alain_Fontaine
    • 2 yrs ago
    • Reported - view

    By definition, an action defined as a "Trigger after update" will only be executed after a field update, and never by itself. So, as you suggest, a global update action must be defined, in addition to the actions performed when updating some fields, triggered by a button or maybe as a "Trigger after open" database option, if you are sure to close and reopen the database each day. Since the passing of time can only advance the status to "2", and never set it back to "1", the script could be:

    (select YourTableName)[days(SendingMailDate, today()) >= 15].('Selection Field' := 2)

    You don't tell what happens when the status has reached state "3". If such records are not to be further updated, the script can become:

    (select Table1)[days(SendingMailDate, today()) >= 15 and number('Selection Field') = 1].('Selection Field' := 2)

    • romdvlp
    • 2 yrs ago
    • Reported - view

    Hi Alain,

    Thank you for your answer. I didn't know the "Trigger after open" option, it could work but, I have too many fields to execute and with too many conditions each time for the same Selection field.

    This will generate too many lines of code in condition knowing, that new fields can be created or old ones changed and it will become too complicated to modify
    Isn't there a "simpler" solution that can be applied directly to each "Trigger after update"? As a lure to the program that thinks the field has been changed/updated and then it triggers its own "Trigger after update"?
    I hope I am clear enough in my explanations. Because the example I gave before was just a simplified example. You have to carry this over to several dozens of fields which, depending on their result in relation to time, will modify a selection field with about 8 types of status.

    • Ninox partner
    • RoSoft_Steven.1
    • 2 yrs ago
    • Reported - view

    Maybe using a formula-field would do the trick since thise don't need a trigger. Using different display views in your formula result might work.

    • romdvlp
    • 2 yrs ago
    • Reported - view

    Fill a formula field with my condition give "This formula can't modify the data"

    Hi RoSoft_Steven Rooryck,

    It's what I thought and tried, but a error message says me that it's not possible to modify the data (the code is a little bit the same than above, it works in the trigger field but in the formula field no...)
    I really don't know how to do...

    • John_Halls
    • 2 yrs ago
    • Reported - view

    That error message is correct, you can't use a formula to change values elsewhere, only its own value. What Steven means is to use formula fields in place of the fields being updated in the trigger.

     

    You would't use a trigger to set all invoices that have become overdue since yesterday. You would have a formula field with if today() > DueDate then "Overdue" end

     

    In addition to this fields can be shown or hidden depending on a value.

    • romdvlp
    • 2 yrs ago
    • Reported - view

    Hi John Hall, thank you for your response !

    But I don't quite understand what you mean.
    Of course I can create a formula field which, depending on this or that event, sends me such and such a message as "Late". I have already done this in particular so that the user enters the information correctly (for example, a message saying that the return date of the email cannot occur before the sending date)

    But I really need a selection field with different status to be impacted by a time bound "trigger". Since depending on its value, I then collect it in a dashboard to differentiate the different progress of my file.
    And this state depends on the time between that of my consultation at the time, and the last updated field (if I fill this field today, I want in 15 days, its progress state to change for example from "In treatment "to" Make a follow-up ").

    • John_Halls
    • 2 yrs ago
    • Reported - view

    Hi Romain

     

    There is nothing you mention in your reply that makes me think you need a trigger to get your dashboard to work. Can you post the code in your trigger?

     

    Thanks John

    • romdvlp
    • 2 yrs ago
    • Reported - view

    Hello John Hall,

    I think I will explain part of what I want to do with the concrete example of my database and tables.

    I have created a table called "File" containing all the information related to the files of my work office, and inside this table, a sub-table called "Connection request" containing a request sent to a network concessionaire which can be electric, gas, drinking water, rainwater, wastewater, etc.

    A file can contain several connection requests, each one different depending on the concessionaire . But a connection request cannot be referenced to several files (hence the idea of the sub-table).

    And if you want, the purpose of my sub-table "Connection request" is to allow a follow-up of these over time according to whether or not such or such step has been executed. So, I have several date fields corresponding to different actions, like for example, the date of sending the connection request to the concessionaire, another field corresponding to the acknowledgement of this request, another one corresponding to a potential dunning date if the concessionaire has not yet acknowledged or has not given any feedback, etc. And there are still many other fields and many other steps.
    So at the beginning of my sub-table I created two selection fields containing different values. The first one is called "Stage of the connection request" defining at what point we are, and the second one is called "Status of the connection request" defining the status as for example "Problem", "Doing a follow up", "In process", etc.

    Capture d’écran 2021-07-02 150346

    (Sorry, I config my database in french because I'm french and it will be used by french persons)

     

    As a result, it is these two elements that I want to modify "automatically" according to what has been updated or not as a field. My problem arises for the modification of the "Status of the connection request" since the time function comes into play. To continue with my examples, I would like my selection field to be updated according to the time when I enter the date on which the connection request was sent to the LoR: if it is less than 15 days from the date of the consultation and the date entered when the request was sent, then it tells me that it is "In process", otherwise it tells me to "Do a reminder".

    Capture d’écran 2021-07-02 150208

    (The code is also in french with french name fields)

    Especially since all this must be done automatically since I want the selection field to inform me later of the status of the file in question (I will have more than 80 files in progress containing an average of 5 connection requests, so I can't have fun consulting them one by one, a dashboard will do it for me thanks to this selection field that I will only have to query thanks to a "select. . where...")

    But this example is only one and it should be applicable to all the other fields that follow.

    If you ask me why I didn't just put a function with a text, the problem is that I want to collect at the end the global state of my file in relation to all its connection requests. So, by collecting all the values of the two selection fields of the connection requests related to the folder, I can keep the one that is the most behind (I filled in the values of the selection fields so that the min(number('Selection Field')) is the one with the smallest or most worrying status) (I'll skip this part). That's why I go through a selection field whose value I can easily retrieve. While I can't "classify" by importance the style of text it will return.

    I hope my explanations are clear enough.

    Romain Zanon 

    • Alain_Fontaine
    • 2 yrs ago
    • Reported - view

    OK, I understand why you wanted to use a choice field. Another possibility is to define EtatAvancement as function field, and to compute its value as a number between 0 and 5, depending on the various conditions. Then, make the field non displayable and define another, displayable, function field, with a formula like:

    styled(item(["Problème", "Relance", "En attente de la prochaine étape"], EtatAvancement), item(["red", "orange", "lavender"], EtatAvancement), item(["white", "black", "black"], EtatAvancement), item(["stop", "question2", "pause"], EtatAvancement))

    I just did the three first values, but you get the idea…

Content aside

  • 2 yrs agoLast active
  • 9Replies
  • 1458Views