how to set Entity teams via js

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • iioi
    Member
    • Jun 2022
    • 48

    how to set Entity teams via js

    Please, how to set teams via js ?
    I what to set entity teams by user teams
    I try to set teamsNames and teamsIds, only teamsNames and so on.

    The result in attach



    full code (last version):

    this.listenTo(this.model, 'change', (model, options) => {
    debugger;
    if (this.model.hasChanged('assignedUserId')) {
    // someAttribute is changed
    this.getModelFactory().create('User', function (model1) {
    model1.id =model.get('assignedUserId');
    model1.fetch().then(function () {
    debugger;

    var teamsNames = model1.get('teamsNames');
    Names = Object.values(teamsNames);
    model.set('teamsNames',Names);
    model.set('teamsIds',model1.get('teamsIds'));
    console.log(model1); // it's fetched
    }.bind(this));
    });
  • Vadym
    Super Moderator
    • Jun 2021
    • 346

    #2
    Hi iioi,

    Could you tell me in more detail what logic you are trying to achieve?
    Perhaps it can be realized by Formula?
    If yes, I will be happy to assist.

    Documentation:
    https://docs.espocrm.com/administrat...culated-fields

    Comment

    • iioi
      Member
      • Jun 2022
      • 48

      #3
      Customer select user, and i want to set Entity teams by user teams. I handle user selection, by i can't set teams in JS code.

      Comment

      • rabii
        Active Community Member
        • Jun 2016
        • 1250

        #4
        you can try and set the teamsIds instead of teamsNames.
        Rabii
        Web Dev

        Comment

        • iioi
          Member
          • Jun 2022
          • 48

          #5
          I've tried this. No result.

          Comment

          • rabii
            Active Community Member
            • Jun 2016
            • 1250

            #6
            try this

            Code:
            this.model.set('teamsNames',Names);
            Rabii
            Web Dev

            Comment

            • iioi
              Member
              • Jun 2022
              • 48

              #7
              Originally posted by rabii
              try this

              Code:
              this.model.set('teamsNames',Names);
              this.model.set('teamsNames',Names); , where Names is Object 62a0627f2adfff704: "TEST1"

              it does not change teams label

              Comment

              • item
                Active Community Member
                • Mar 2017
                • 1476

                #8
                Hi,
                try this ..maybe use "this" :

                var modelData = {};
                modelData.teamsIds = model1.get('teamsIds') || [];
                modelData.teamsNames = model1.get('teamsNames') || {};
                model.set(modelData);
                If you could give the project a star on GitHub. EspoCrm believe our work truly deserves more recognition. Thanks.​

                Comment

                • iioi
                  Member
                  • Jun 2022
                  • 48

                  #9
                  Originally posted by item
                  Hi,
                  try this ..maybe use "this" :

                  var modelData = {};
                  modelData.teamsIds = model1.get('teamsIds') || [];
                  modelData.teamsNames = model1.get('teamsNames') || {};
                  model.set(modelData);
                  Thsnks a lot! It works!

                  Comment

                  Working...