Solved

Execute default procedure on edit


Userlevel 1
Badge +2

Hi,

 

I want to fill some values in a form on the moment that the user starts editing. I wanted to do this in the default procedure, but this is only executed after an edit has happened and not on the moment that the edit button is pressed (like the layout procedure).

 

Is there a solution for this in thinkwise?

 

Thanks

icon

Best answer by Mark Jongeling 4 November 2021, 08:40

View original

10 replies

Userlevel 7
Badge +23

Hi,

That indeed is something that does not happen. Due to also supporting auto-edit and auto-save mode, it can lead to unforeseen effects if the default would suddenly changes values.

Could a Column Default value be of any help? You can set default values in Data Model > Tables, but also in Subject > [Your table] → This way you can deviate on specific screens.

Userlevel 1
Badge +2

Hi Mark,

This does not seem to work.

Maybe the default value for a specific column is only filled when the column is empty?

I would like to do something like this: 

Here someone is talking about some dynamic model weaving. Can you elaborate more on this?

How can I implement this?

 

Thanks,

Peter

Userlevel 7
Badge +23

Hi Peter,

Strange, for me it functions like I meant it. The second part in only for Variants, I missed that in my first reply. When going to Subjects > Variants > Columns, you can adjust the Default value:

Subjects > Variants > Columns

GIF of autofill:

Autofill default value

Maybe the default value for a specific column is only filled when the column is empty?

If your Default procedure changes the value upon Adding a new row, then yes it will overwrite the Data model/Subject column default value.

 

Here someone is talking about some dynamic model weaving. Can you elaborate more on this?

What my colleague is suggesting is to make sure that for each datetime field, the inputted datetime is converted to UTC + when data is accessed, that the user sees the local time. How to really implement it, depends on your preference. 

If I had to tackle this, I would probably go for input fields that are always in the local time. During Navigation it will show an expression field that converts the saved UTC date to the local time. The local time should be saved in a sort of User preference table inside the end product. During adding and editing, it will show the input field that does not contain any value on the database, but will get filled by the default procedure.

Sadly this does limit you to only using Forms as your main input method as you cannot hide fields in the Grid with a Layout procedure. 

In short, the screen will have (per intended datetime column):

  • Expression field for showing the local datetime during navigation
  • Input field to input local datetime during adding and editing
  • UTC datetime field that isn't visible but is present in the database table

The dynamic model weaving is to automate parts of the model creation. For instance, for every column that used DATETIME, create an expression column and an UTC column.

Userlevel 1
Badge +2

Hi Mark,

 

Thanks for you reply.

 

I think I forgot the tell you what I have right now. And some background.

 

I need the timezone fields for the planners in our company. We are doing tours with trucks. Those tours can happen in multiple timezones but overall the planners are based in NL. Therefore I want to show 2 time fields. 1 with the local time of the planner and 1 with the local time where the tour is happening. 

 

My plan was to make 1 database fields with the UTC time and show the local fields in ‘Navigate’ mode. Once the user clicks edit, it should show the database field. However, because the planner needs to plan in his own time and not in UTC time, I want to update the database field in The ‘On Edit’ modus. And that is what my question is about, I cannot update the database field in Edit modus.

 

One more thing, after the user has filled the database field, I have created a trigger where I convert the entered time of the employee to UTC time, based on the timezone where the employee lives. 

 

To summarize, my idea is to update the database field with the local time of the employee, on the moment that the employee clicks edit. Is this possible in edit modus? In you example I see you are filling the default value when adding a new record. Can I make the default value also work when I am in edit mode? 

 

Thanks,
Peter

Userlevel 7
Badge +23

Hi Peter,

The Default procedure does not trigger upon clicking Edit as we also support auto edit-mode. If then Default procedures would activate for each row, it can lead to undesired effects, but I do see the added value in that in this case.

I'm not sure if your users could works with my following idea but what you could do is to let your users fill in the datetime in UTC and next to it show a local (Expression) field that converts the inputted time to the user's local time. That way you wouldn't have to lean on triggers writing away the correct UTC time or such; the time inputted will always be UTC and next to it show a local time version. Could that be a workaround? During Navigation you could opt for not showing the UTC time field.

Userlevel 1
Badge +2

Hi Mark,

Thanks for you suggestion! I understand the reason why the default proc is not executed on Edit. 
I will discuss your idea with our team and let you know the outcome.

Peter

Userlevel 1
Badge +2

Hi Mark,

I discussed the solution with the product owner. He does not like this solution, because the people that will work with this will not accept this solution.

I tried to dive more into your solution where you set the default value in a table variant. However this only works when creating a record. And not when editing, even when the field is empty. It will not fill the field with the value specified in the expression.

Can you suggest?

 

Peter

Userlevel 7
Badge +23

I tried to dive more into your solution where you set the default value in a table variant. However this only works when creating a record. And not when editing, even when the field is empty. It will not fill the field with the value specified in the expression.

Can you suggest?

Only way of solving this now is by using Tasks to set the form to edit mode instead of the GUI button. When clicking a Task, you could set the selected record in Edit mode and set the value of a certain column to a certain value in the Edit row process action input parameters; basically replacing a default procedure on click with the process action.

Edit row input - use Variable to make it variable

Hope this helps out. I understand that having to use Tasks instead of GUI button is a pity. We do have a backlog item to support this exact behavior (CRUD Tasks).

Userlevel 1
Badge +2

Hi Mark,

Thanks! This works like a charm!

Only one thing I am now left with.

I cannot disable the GUI edit button, if I do that the task will not work anymore.

Any suggestion on how to solve this?

Peter

Userlevel 7
Badge +23

Hi,

Yes, that is a pity as the Edit row will activate the Edit mode of the form so disabling the button will counter that. Workaround is to disable the Edit button with the Layout procedure and re-enabling it when the Task is executed. You'll need a value somewhere (for instance in the row you want to edit) that either dictates if the Edit button is available or not. After executing the Task, that value will change from 0 to 1, refresh the Table (to activate the Layout procedure once again) and the Edit button should be available. Then when the user stops or finishes editing, change the value back to 0.

If the Form is not too large, you could let the Task be your Form. Then adding can happen via the Form but editing can only happen by selecting the Task and filling in values in there. I can see that this could be undesirable.

Hope this helps!

Reply