Extends Chat Message, issue with model data

I intend to extends ChatMessage to add a field to the schema. and then add it to the renderTemplate data to be shown.
But during the "getHTML" function the value that I added to the schema is always empty.
Do I have to setup something else to make it reach getHTML with the proper value ?

The class extending the ChatMessage
export default class MyChatMessage extends ChatMessage {
    static defineSchema() {
        return {
            ...super.defineSchema(),
            postcontent: new foundry.data.fields.HTMLField({ textSearch: true }),
        };
    }

    async getHTML() {
        console.log("getHTML");
        console.dir(this);
        return super.getHTML();
    }

}


Inside my "init" hook
    CONFIG.ChatMessage.documentClass = documents.MyChatMessage;
    CONFIG.ChatMessage.template = "systems/mysystem/templates/chat_messages/chat_message.hbs";


The calling code
        ChatMessage.create({
            speaker: ChatMessage.getSpeaker({ actor: this }),
            user: game.user.id,
            type: CONST.CHAT_MESSAGE_TYPES.ROLL,
            sound: CONFIG.sounds.dice,
            rolls: [roll],
            content: "<div>Content</div>",
            postcontent: "<div>PostContent</div>"
        }, { rollMode: roll_mode });
Was this page helpful?