Hi everyone!
How are you? I hope you can help me.
I need the default image of the employee to change dynamically depending if gender is Female O Male when the Photo not is set. I saw that the attribute Photo on Employee refers to Contact.Photo in attributes section of EmployeePage(Base)
How can I do this?
King Regards,
Ezequiel
Like
Dear Ezequiel,
You can achieve such task by applying some code modifications to the ContactPageV2. Please create or open ContactPageV2. Go to localizable strings (menu on the right) and add to Images your icon for female contacts.
Afterwards, please use this example to apply code modifications:
define("ContactPageV2", ["ContactPageV2Resources"], function(resources) { return { entitySchemaName: "Contact", attributes: { "DefaultImage": { dataValueType: Terrasoft.DataValueType.TEXT, type: Terrasoft.ViewModelColumnType.VIRTUAL_COLUMN } }, methods: { onEntityInitialized: function() { this.callParent(arguments); this.setPhoto(); }, setPhoto: function() { var primaryImageColumnValue = this.get(this.primaryImageColumnName); if (!primaryImageColumnValue) { var gender = this.get("Gender").value; if (gender === "fc2483f8-65b6-df11-831a-001d60e938c6") { document.getElementsByClassName("ts-image-edit-full-size-element ts-image-style-rectangular")[0] .setAttribute("src", Terrasoft.ImageUrlBuilder.getUrl(resources.localizableImages.DefaultPhotoFemale)); } else { document.getElementsByClassName("ts-image-edit-full-size-element ts-image-style-rectangular")[0] .setAttribute("src", Terrasoft.ImageUrlBuilder.getUrl(resources.localizableImages.DefaultPhoto)); } } } }, diff: /**SCHEMA_DIFF*/[ ]/**SCHEMA_DIFF*/ }; } );
Here you can see, that based on the gender of the contact, the icon is set. Also, you can improve the code by adding onChange statement, which can change the icon if gender changes in runtime.
Regards,
Anastasia
Anastasia Botezat,
one question
How can set image when onentityinitialized event is not triggered?