Question

Default value for custom objects ?

Hi (again),

 

I need to set a default value for an attribute (Lookup Id), in a custom object.

The problem is that this attribute is in "read only" since it is filled in (with a Business rules). 

I tried something like that:

init: function() {
	this.callParent(arguments);
	if (this.isNewMode()) {
		var default = "id of my default value, which is a lookup id";
		this.set("MyLookup", default);
		this.reloadEntity();
	}
}

When I access "MyLookup" value (before saving) with "this.get()", it gaves me the correct value, but it seems my object hasn't refresh or something. Maybe I don't put my Id correctly?

 

Thanks

Like 0

Like

2 comments

Dear Jean,

First, you can set default value for a new object in the object schema:

Second, if you want set values depending on some other values, you should do it not in Init() function because there is no entity there, but in onEntityInitialized(). Example from Contact page:

onEntityInitialized: function() {

                        this.setIsEmailDetailVisible();

Third, don't use this.reloadEntity() because it reloads fields from the database, So it overwrites all the changes on the page.

Thanks you Peter, it solved my problem.

I don't know why I was lookup for something that complicated, your solution is what I was lookup for.

Show all comments