Announcement

Collapse
No announcement yet.

Populate related item fields and output them

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Populate related item fields and output them

    Hello.
    I have simple relation in CRM:
    I have Orders instance, where have relation to Manager instance.

    Orders fields:
    Title, Manager(relation)
    (Example: Title: Test title, Manager: John)

    Manager fields:
    Name, Email
    (Example: Name: John, Email: email@example.com)

    I have a list of orders. It's a simple standard table where I have this columns:

    ID|Order title|Manager
    1 | Test title | John

    What I need is to output not only name of manager, but and his email in this orders list:

    ID|Order title|Manager
    1 | Test title | John (email@example.com)

    What is the best solution to output not only Name, but and other relation fields in table, in my case email?

  • #2
    Like this

    Comment


    • #3
      You could make a new "External" type field and select the link (Manager) and then select the field Email Address.and then add it to the desidered layout

      Comment


      • #4
        Originally posted by Kharg View Post
        You could make a new "External" type field and select the link (Manager) and then select the field Email Address.and then add it to the desidered layout
        In this case I can put email in the another column, but I want to put it in the same column, with the Manager Name.
        For now I created custom view for manager field:
        in my entityDefs/Orders.json:
        Code:
        ...
        "manager": {
        "type": "link",
        "view": "custom:views/order/fields/contact-field"
        },
        ...
        in my contact-field.js:
        Code:
        define(
        "custom:views/order/fields/contact-field",
        "views/fields/link",
        function (Dep) {
        return Dep.extend({
        setup: function () {
        Dep.prototype.setup.call(this);
        // some initialization
        },
        afterRender: function () {
        Dep.prototype.afterRender.call(this);
        // your customizations executed after the field is rendered
        },
        data: function () {
        console.log(
        "this.idName",
        this.idName,
        "this.nameName",
        this.nameName,
        "this----",
        this
        );
        var nameValue = this.model.has(this.nameName)
        ? this.model.get(this.nameName)
        : this.model.get(this.idName);
        if (nameValue === null) {
        nameValue = this.model.get(this.idName);
        }
        if (this.isReadMode() && !nameValue && this.model.get(this.idName)) {
        nameValue = this.translate(this.foreignScope, "scopeNames");
        }
        var iconHtml = null;
        if (this.mode === "detail") {
        iconHtml = this.getHelper().getScopeColorIconHtml(this.foreig nScope);
        }
        console.log("nameValue", this.model);
        let datat = Dep.prototype.data.call(this);
        let dataresult = _.extend(
        {
        idName: this.idName,
        nameName: this.nameName,
        idValue: this.model.get(this.idName),
        nameValue: nameValue,
        foreignScope: this.foreignScope,
        valueIsSet: this.model.has(this.idName),
        iconHtml: iconHtml,
        },
        Dep.prototype.data.call(this)
        );
        console.log("dataresult", datat);
        return dataresult;
        },
        });
        }
        );
        how can I populate all relation fields, not only name here?

        Comment


        • #5
          if you have a relationship then you can add a foreign field on the order entity and select the manager entity and then select the email field. this should import the email of the linked manager into the order. assuming you have a One Manager Has Many Orders, this should work. go to entity manager/ order/ add field and select foreign and then from the relation list chose the manager and then select the email field.

          Comment

          Working...
          X