telecastg For Address it is working fine.
I want another field like Name which will display addressPostalCode4 and addressPostalCode in one field and also able to export in the report.
Can anyone help me out in this?
Custom Field Like Name
Collapse
X
-
Leave a comment:
-
telecastg
I have to store zip code 5 and zip code 4 in different fields. So I have customized the address to support zip codes 4 and 5 and it's working fine.
I am doing all this for Reporting purposes. I need to create a PostalCode field like Name which will merge the addressPostalCode4 and addressPostalCode and export the same in the report. (like how the name field is working)
Can anyone help me? Is it possible to do?Leave a comment:
-
I think that it will help understanding the way "complex" fields like "address" or "personName" work in Espo.
The attribute/field "address" is a complex virtual "field" (not a real database table column) made up of five real/actual model attributes/fields (sub-fields) "street", "city", "state", "country" and "postalCode".
When you add an "address" attribute/field to an entity ("Contact" for example), Espo prepends the word "address" to the actual field names, since they are sub-fields of "address", and adds then five properties to the model: "addressStreet", "addressCity", "addressState", "addressCountry" and "addressPostalCode", so to get one of these values, "street" for example, you would writeCode:this.model.get('addressStreet');
The solution that I posted was for your original goal of creating an independent field, and thus creates a complex field "postalCodes" that is made up of two "sub-fields":
1) "postalCode4" which is the field where you store the additional 4 digits for the zip code and becomes "postalCodesPostalCode4" entity attribute and "postal_codes_postal_code4" database field.
2) "postalCode" which becomes "postalCodesPostalCode" attribute and it is not an actual database field, but a runtime reference to the value contained in the entity's attribute "addressPostalCode".
Notice how these two attributes are prepended with "postalCodes" because they are sub-fields of "postalCodes".
As I mentioned in my post, one of the possible improvements was to modify the "address" field to incorporate the zip plus 4 capability instead of using a stand alone field like "postalCodes", and I think that this is what you are trying to accomplish now.
To do that you will need to create a custom "addressPlus4" field cloning the existing "address" field type and making the necessary modifications to incorporate an actual zip4 field, then you will need to substitute the field "address" for "addressPlus4" in all entities where you want to display the zip plus 4 capability.
With regards to displaying it in reports, we don't have the advance pack so I can't help you with that part.
One question is why do you need to have two separate fields for zip code ?. Unless you have a specific need to segregate the zip code information, you could just enter the complete string in the existing postalCode field instead of creating a whole new "address" custom field.Last edited by telecastg; 12-01-2020, 12:31 AM.Leave a comment:
-
telecastg
I have customized the address which will add the addressPostalCode4 to it.
I am trying to create the postalCodes which will show the addresspostalCode4 and addressPostalCode in one field. (Like name, address).
But in the list view, the value is coming like undefined -undefined. If I add addressPostlCode and addressPostalCode4 to the list view then only it will come. I don't want that. Also, the value should be exported in the reports.
Because
Code:this.model.get(this.postalCode4Field)
espocrm/custom/Espo/Custom/Resources/metadata/fields/postalCode.json
Code:{ "view": "custom:views/fields/postal-code", "actualFields":[ "addressPostalCode4", "addressPostalCode" ], "notActualFields": [ "" ], "params":[ { "name":"required", "type":"bool", "default":false } ], "fields":{ "addressPostalCode4":{ "type": "varchar", "trim": true, "maxLength": 40, "select": { "select": "addressPostalCode4" } }, "addressPostalCode":{ "type": "varchar", "trim": true, "maxLength": 40, "select": { "select": "addressPostalCode" } } }, "notMergeable":true, "notCreatable":true, "filter":true, "skipOrmDefs": true, "personalData": true }
Leave a comment:
-
Do you mean the screen capture images ?, they show up fine in my computer ???
UPDATE: I can't see the former screen captures either... not sure why and don't have them in my computer anymore, so I removed them from the positingLast edited by telecastg; 03-02-2021, 05:51 PM. -
telecastg The solution is not working for me!!
I did some modifications still I have the same problem with the value.
The modified table for "Contact" will have a new field "postal_code_postal_code4" where you store the zip code extra 4 digits, "postalCode" is a runtime reference, not an actual database field.Leave a comment:
-
telecastg The solution is not working for me!!
I did some modifications still I have the same problem with the value.
What is that
PHP Code:"actualFields":[ "postalCode4" ], "notActualFields": [ "postalCode" ],
Leave a comment:
-
I managed to incorporate the custom "postalCode" type field to the Contact entity and display in both list and detail modes using the following scripts:
1) Custom field metadata definition:
custom/Espo/Custom/Resources/metadata/fields/postalCode.json
Code:{ "view": "custom:views/fields/postal-code", "actualFields":[ "postalCode4" ], "notActualFields": [ "postalCode" ], "params":[ { "name":"required", "type":"bool", "default":false } ], "fields":{ "postalCode4":{ "type": "varchar", "trim": true, "maxLength": 40 }, "postalCode" :{ "type": "varchar", "trim": true, "maxLength": 40, "notStorable": true, "select": { "select": "addressPostalCode" } } }, "notMergeable":true, "notCreatable":true, "filter":true, "skipOrmDefs": true, "personalData": true }
client/custom/src/views/fields/postal-code.js
Code:define('custom:views/fields/postal-code', 'views/fields/varchar', function (Dep) { return Dep.extend({ type: 'postalCode', init: function () { Dep.prototype.init.call(this); this.postalCode4Field = 'postalCodesPostalCode4'; this.postalCodeField = 'postalCodesPostalCode'; }, data: function () { var data = Dep.prototype.data.call(this); data.postalCode4Value = this.model.get(this.postalCode4Field); data.postalCodeValue = this.model.get(this.postalCodeField); if (this.mode === 'detail') { data.isNotEmpty = !!data.postalCode4Value || !!data.postalCodeValue; } else if (this.mode === 'list' || this.mode === 'listLink') { data.isNotEmpty = !!data.postalCode4Value || !!data.postalCodeValue; } if (data.isNotEmpty && this.mode == 'detail' || this.mode == 'list' || this.mode === 'listLink') { data.formattedValue = this.getFormattedValue(); data.value = data.formattedValue; } data.valueIsSet = this.model.has(this.postalCode4Field) || this.model.has(this.postalCodeField); return data; }, getFormattedValue: function () { var code4 = this.model.get(this.postalCode4Field); var code = this.model.get(this.postalCodeField); var value = ''; value += ' ' + code; value += '-' + code4; value = value.trim(); return value; }, }); });
custom/Espo/Custom/Resources/metadata/entityDefs/Contact.json
Code:{ "fields" : { "postalCodes": { "type": "postalCode", "view": "custom:views/fields/postal-code", "readOnly": true, "inlineEditDisabled": true } } }
custom/Espo/Custom/Resources/layouts/Contact/list.json
Code:[ { "name": "name", "link": true }, { "name": "phoneNumber" }, { "name": "emailAddress", "width": 20, "notSortable": true }, { "name": "postalCodes" } { "name": "tenancies", "notSortable": true } ]
Code:[ { "rows": [ [ { "name": "name" }, false ], [ { "name": "phoneNumber" }, { "name": "emailAddress" } ], [ { "name": "address" }, { "name": "postalCodes" } ] ], "style": "default", "label": "Overview" } ]
custom/Espo/Custom/Resources/i18n/en_US/Contact.json
Code:{ "fields": { "postalCodes": "Postal Codes" } }
This solution works with Espo 6.0.4 in a test local site
I am very busy right now refactoring our extensive custom code to work with Espo 6+ so I didn't have time to do it, but I believe that a complete solution would require additionally:
a) A zip4 field input control (the field is read-only at present) to enter Contact information manually
b) Testing and if necessary develop code for searching or exporting
c) Optionally develop a custom "address" definition that incorporates the zip+4 new field instead of the current "addressPostalCode" field
I also did not use the ORM field class because it wasn't necessary for my solution and also because like you, I couldn't figure out how to invoke the class like its done for the "personName" field type.
As I understand, the custom field ORM definition is supposed to be called by the "correctFields()" function in the "Converter" class but I could not get the custom field ORM class to fire. Not sure if its some kind of a bug or just my lack of knowledge
If you make changes/improvements to this solution please post them here to benefit everyone else.Last edited by telecastg; 03-02-2021, 05:50 PM.Leave a comment:
-
I have uploaded the above-listed files in txt format.- postaCodeJS.txt => espocrm/client/custom/src/views/fields/postalCode.js
- PostalCodeJson.txt => espocrm/custom/Espo/Custom/Resources/metadata/fields/postalCode.json
- PostalCodeOrm.txt => espocrm/custom/Espo/Custom/Core/Utils/Database/Orm/Fields/PostalCode.php
Leave a comment:
-
Won't be able to help you with either of the question but I have two tip that might help you progress a bit instead:
(1) have a look Real Estate extension that might be helpful ( https://www.espocrm.com/extensions/real-estate/ );
(2) secondly is to test it with other address field to see if it work, e.g. try Street, or State, or Country or City. One issue Postcode is it doesn't support Auto-complete/Options. But State, Country and City support that (see admin > settings > Address City Autocomplete List ) or URL: /#Admin/settings/
And I'm not sure if it relevant to what you trying to do. It might just be the field Postal Code that causing you to fail rather than the coding itself.Leave a comment:
-
I don't use the advanced pack so I can't help you with reports but I can try to help solving the "undefined" issue in list view.
Could you please post the code for the files that you created ?Leave a comment:
Leave a comment: