Get model attributes in dynamic controller

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jgarcia
    Junior Member
    • Aug 2023
    • 18

    Get model attributes in dynamic controller

    Hello everyone,

    Could you help me with the following problem please. I am creating a dynamic controller for "Case" but when I try to get a model attribute in the following way "this.model.get('type')" or in this way "this.recordView.model.get('type') "The first time I enter a record after rebuilding, deleting the cache and reloading the page, it shows me "undefined" in the console but if I exit and re-enter the same record it shows me the correct data.

    What can I do to always get the correct data?

    this is the code I'm using

    HTML Code:
    define('custom:case-dynamic-handler', ['dynamic-handler'], (Dep) => {
    
        return class extends Dep {
    
            init() {
                this.controlEnum();
            } 
           
            controlEnum() {
                console.log(this.model.get('type'));
                console.log(this.recordView.model.get('type'));
            }
        }   
    });
    Attached Files
  • dimyy
    Active Community Member
    • Jun 2018
    • 569

    #2
    Try this.view... (this.view.model etc)

    Comment


    • jgarcia
      jgarcia commented
      Editing a comment
      Thanks for your help, but if I use "this.view.model", "this.view" or "this.view.model.get('type')" I still get the undefined value.
  • rabii
    Active Community Member
    • Jun 2016
    • 1250

    #3
    this.model.get('type') should work fine. i have just tested your code on my instance and it works fine. check if the value of type is none
    Rabii
    Web Dev

    Comment

    Working...