[SOLVED] Change text shown in a formgrid? (Need to make text replacement from SQL val

Hi there-
Suppose that, in the database, we have a field with text values like STORE001_Sobeys, STORE002_MyStoreName, STOREZ4D_JohnsStore

How do we create a function that lets us change each value as it is displayed in the form grid, to:
Sobeys, My Store Name, John’s Store

Then, if the value is saved, we’d run a function to save it as the correct value (STORE0001_Sobeys, etc) in the database.
We don’t want to have a lookup table, unless that’s truly the only way… There are too many different values and possibilities and they change all the time. We’d rather write a PHP function.

Actually I would go for two fields in the database. I guess that STORE001 is in fact the primary key and Sobeys the description? But I guess that you use the full fieldname as a foreign elsewhere. First of all you need to add two fields in your form, one for both parts. Then in the onload event you split the text by the underscore and fill the appropiate two new fields. See php explode statement for this.

Then just onbeforeinsert / update you need to merge these two fields together and fill the original field with this. Then the correct value is put into the database.

But keep in mind that you cannot change primary keys in SC. That is, if these fields are part of it of course.

Would that be the onLoad event or the onLoadRecord event?
How exactly do I set the field values in the onLoad event? What’s the PHP code to do that? (I’m a bit new)
Also, how do I do the updating in the onBeforeInsert?
Thanks!

You need to do that for all records individually. So in this case I suggest onloadrecord. Assigning fieldvalues is php style: {myfield}={field1}.’_’.{field2};

Thanks! Works!