Добрый день!
Пытаюсь создать Лид из коммуникационной панели(email-сообщения).
Создается пустая запись, заполняется только поле "ФИО Контакта" (даже адрес email не заполняется)
Вопрос в следующем: Каким образом при создании новой записи можно заполнить необходимые мне поля из email-сообщения (адрес email, источник и т.п.)?
![]()
Нравится
Максим, эта логика реализована в схеме EmailItemSchema пакета UIv2. Там есть функции addEmailRelation и getRelationValuePairs, которые готовят открытия окна и предзаполняют значения полей.
Стандартно эти функции такие:
/**
* Handles "Add relation" menu item click.
* @protected
* @param {String} columnName Connection column name.
*/
addEmailRelation: function(columnName) {
this.set("EntityRelationColumnName", columnName);
var moduleStructure = this.Terrasoft.configuration.ModuleStructure;
var schemaName = this.getSchemaNameByRelationColumnName(columnName);
var schemaModuleStructure = moduleStructure[schemaName];
var schemaPages = schemaModuleStructure.pages;
var cardSchema = schemaModuleStructure.cardSchema;
var defaultValues = this.getRelationValuePairs(columnName, schemaName);
if (this.Ext.isArray(schemaPages)) {
var cardInfo = this.Terrasoft.findWhere(schemaPages, {name: schemaName});
cardSchema = cardInfo.cardSchema;
if (schemaModuleStructure.attribute && cardInfo.UId) {
defaultValues.push({
name: schemaModuleStructure.attribute,
value: cardInfo.UId
});
}
}
var moduleId = "AddEmailRelation_" + cardSchema + this.Terrasoft.generateGUID();
this.sandbox.subscribe("CardModuleResponse", this.cardModuleResponseHandler, this,
[moduleId]);
var openCardConfig = {
schemaName: cardSchema,
operation: this.Terrasoft.ConfigurationEnums.CardOperation.ADD,
moduleId: moduleId,
defaultValues: defaultValues,
renderTo: "centerPanel",
keepAlive: true
};
this.openCardInChain(openCardConfig);
},
...
/**
* Returns default value array for relation entity.
* @protected
* @param {String} columnName Connection column name.
* @param {String} schemaName Connection schema name.
* @return {Object[]} Default value array for relation entity. Array element contains
* column name and its value.
*/
getRelationValuePairs: function(columnName, schemaName) {
var contact;
var valuePairs = [];
var entitySchema = this.entitySchema;
if (entitySchema.name === schemaName) {
valuePairs.push({
name: entitySchema.primaryDisplayColumnName,
value: this.get("MailTitleText")
});
}
if (this.get("Contact")) {
contact = this.get("Contact");
if (this.get("Account")) {
contact.Account = {
value: this.get("Account").value,
displayValue: this.get("Account").displayValue
};
}
}
var account = this.get("Account");
if (!contact && account) {
valuePairs.push({
name: "Account",
value: this.getEntityDefaultValueColumnValue(schemaName, account)
});
return valuePairs;
}
if (!contact) {
contact = this.get("SenderContact");
}
if (contact && contact.value) {
valuePairs.push({
name: this.getSchemaDefaultValueColumnName("Contact", schemaName),
value: this.getEntityDefaultValueColumnValue(schemaName, contact)
});
var senderAccount = contact.Account;
if (senderAccount) {
valuePairs.push({
name: this.getSchemaDefaultValueColumnName("Account", schemaName),
value: this.getEntityDefaultValueColumnValue(schemaName, senderAccount)
});
}
}
if (columnName === "Contact" && this.isAutoBindingContactEmailNeeded()) {
this.addSenderInfo(valuePairs);
}
return valuePairs;
},
Во второй функции есть специальная логика для полей контактов и контрагентов. Вы можете переопределить в своём пакете и добавить в эту функцию для своего раздела получение и внесение через valuePairs.push ещё нескольких полей.
Максим, эта логика реализована в схеме EmailItemSchema пакета UIv2. Там есть функции addEmailRelation и getRelationValuePairs, которые готовят открытия окна и предзаполняют значения полей.
Стандартно эти функции такие:
/**
* Handles "Add relation" menu item click.
* @protected
* @param {String} columnName Connection column name.
*/
addEmailRelation: function(columnName) {
this.set("EntityRelationColumnName", columnName);
var moduleStructure = this.Terrasoft.configuration.ModuleStructure;
var schemaName = this.getSchemaNameByRelationColumnName(columnName);
var schemaModuleStructure = moduleStructure[schemaName];
var schemaPages = schemaModuleStructure.pages;
var cardSchema = schemaModuleStructure.cardSchema;
var defaultValues = this.getRelationValuePairs(columnName, schemaName);
if (this.Ext.isArray(schemaPages)) {
var cardInfo = this.Terrasoft.findWhere(schemaPages, {name: schemaName});
cardSchema = cardInfo.cardSchema;
if (schemaModuleStructure.attribute && cardInfo.UId) {
defaultValues.push({
name: schemaModuleStructure.attribute,
value: cardInfo.UId
});
}
}
var moduleId = "AddEmailRelation_" + cardSchema + this.Terrasoft.generateGUID();
this.sandbox.subscribe("CardModuleResponse", this.cardModuleResponseHandler, this,
[moduleId]);
var openCardConfig = {
schemaName: cardSchema,
operation: this.Terrasoft.ConfigurationEnums.CardOperation.ADD,
moduleId: moduleId,
defaultValues: defaultValues,
renderTo: "centerPanel",
keepAlive: true
};
this.openCardInChain(openCardConfig);
},
...
/**
* Returns default value array for relation entity.
* @protected
* @param {String} columnName Connection column name.
* @param {String} schemaName Connection schema name.
* @return {Object[]} Default value array for relation entity. Array element contains
* column name and its value.
*/
getRelationValuePairs: function(columnName, schemaName) {
var contact;
var valuePairs = [];
var entitySchema = this.entitySchema;
if (entitySchema.name === schemaName) {
valuePairs.push({
name: entitySchema.primaryDisplayColumnName,
value: this.get("MailTitleText")
});
}
if (this.get("Contact")) {
contact = this.get("Contact");
if (this.get("Account")) {
contact.Account = {
value: this.get("Account").value,
displayValue: this.get("Account").displayValue
};
}
}
var account = this.get("Account");
if (!contact && account) {
valuePairs.push({
name: "Account",
value: this.getEntityDefaultValueColumnValue(schemaName, account)
});
return valuePairs;
}
if (!contact) {
contact = this.get("SenderContact");
}
if (contact && contact.value) {
valuePairs.push({
name: this.getSchemaDefaultValueColumnName("Contact", schemaName),
value: this.getEntityDefaultValueColumnValue(schemaName, contact)
});
var senderAccount = contact.Account;
if (senderAccount) {
valuePairs.push({
name: this.getSchemaDefaultValueColumnName("Account", schemaName),
value: this.getEntityDefaultValueColumnValue(schemaName, senderAccount)
});
}
}
if (columnName === "Contact" && this.isAutoBindingContactEmailNeeded()) {
this.addSenderInfo(valuePairs);
}
return valuePairs;
},
Во второй функции есть специальная логика для полей контактов и контрагентов. Вы можете переопределить в своём пакете и добавить в эту функцию для своего раздела получение и внесение через valuePairs.push ещё нескольких полей.