How I can load value

4.0
How I can load value
0
Tags: #<Tag:0x00007fc3d2221008>
#1

How I can load value in form and put it in text.

0 Likes

#2

0 Likes

(David AZOULAY) #3

preCreate

Calling a save in a postSave does not make sense !

Chances are it will result in a stackoverflow (unless you do tricky things to avoid it, which does not seems to be the case here).

The code you have written in the postCreate should rather be in the pre/postValidate

postLoad

The code you have written in the postLoad does not make sense either,

There seems to be a misunderstanding of the role of this hook which is only dedicated to set “static” rules for the user and/or object instance. It does not make sense to set values int this hook.

Please refer to https://docs.simplicite.io/documentation/01-core/businessobject-code-hooks.md for explanations on the role of each business objects hooks.

0 Likes

#4

ok, but how I can Load value !!!

0 Likes

(David AZOULAY) #5

A field value is set by a this.setFieldValue("<field name>", "<value>") or this.getField("<field name>").setValue("<value>").

When you need to set a field using server-side code you can do it either in a initCreate/Update hook or in a pre/portValidate or both depending on what you want to do.

If you want to prepare your record before it is displayed as a form then you can use the initCreate/update approach. If the value is defined by a business rule you must do it in the pre/postValidate

Keep in mind that what is displayed on a webpage can easily be altered, so most of the time you can’t rely only on what you do in a initCreate/Update you must redo it in the pre/postValidate.

To set a value you can also use the default value mechanism, for instance if your requirement is to set a field with the current date you can set [DATE] as default value of this field, the value will be set by the platform. Etc.

1 Like

(David AZOULAY) #6

PS: There are many examples of get/set values in https://docs.simplicite.io/documentation/01-core/businessobject-code-hooks.md. I insist on the fact that the role of the hooks must be well understood to get what you want (for instance setting an object field value in the object’s postCreate does not make sense and it is normal that you don’t get any visible effect from this code, same for the postLoad hook where setting a field value does not make sense at all. I think the one you looked for was rather the initCreate or maybe the postSelect)

0 Likes

#7

Thank you for your help

0 Likes