Employee custom field value doesn't save

I have a custom field that I created programmatically for Employees. I added it to the detail and and edit views through Studio. But when I try to save an employee record the value for my custom field isn’t saved, but the other fields are.

The field is just a regular text field. I know that the employees module uses the users table, so then I tried creating it as a User field instead, but it still doesn’t work. Here is the field def:

$dictionary['User']['fields']['unit'] = array(
	'name' => 'unit',
	'type' => 'varchar',
	'studio' => true,
	'len' => 16,
	'vname' => 'LBL_UNIT',
);

Hi,

Please do the repair and make sure repair should be query free.

Check the SuiteCRM log after creating or updating any user.

If you still face the problem please let me know. Thank you!

I forgot to mention that I tried that. But what do you mean by the repair should be query free?

This time I did the repair, I scrolled to the bottom and I noticed that it said the database was out of sync with the customizations… Not sure why that happens? Anyway I clicked execute on that and it said I had a syntax error in the query… so I guess the problem was the custom field was never being created in the database.

So looks like you’ve pointed me in the right direction anyway, thank you!

It turns out the mySQL error was actually from a different module. I fixed that, but the problem is still persisting.

I checked the php and suitecrm logs and don’t see any errors, although I notice that in the UPDATE query unit is being set to NULL…

Have you placed the custom field correctly in the following path?

custom/Extension/modules/Users/Ext/Vardefs/sugarfield_unit.php (the last part is file name that you can set to anything)

Make sure to Run Repair/Rebuild after placing the file at above path.

Yes the field is defined in that directory, but it isn’t named starting with “sugarfield_”. Are you sure that it has to? The developer docs don’t mention this.

But do I see that the field def is being generated in custom/modules/Users/Ext/Vardefs/vardef.ext.php, so does that not mean that it’s working?

Bump…

So one weird thing is that when you edit the field inline, it saves that way. But when you edit the whole case, the field’s value is set to the old value.

Any ideas?

The file doesn’t need to be called sugarfield_etc, and the fact that the change is picked up in the generated file is sufficient evidence for this.

I suspect you’re hitting some problem with the strange interaction between Employees and Users… maybe your field needs to be added in more than one place. But I am just speculating. I don’t know.

Why did you create the field programmatically in the first place? Can’t you add it from Studio?

Well the reason I created it programmatically is I guess because I find Studio to be a bit clunky, and I just prefer to know exactly what I’m doing. Anyway that being said, I just created another field in Studio (but under Employees, not Users this time) and it works completely fine. Definitely something strange going on, but I guess this is a good enough work-around in this case.