Partekatu honen bidez:


Crear y actualizar una entidad que se puede enviar por correo electrónico

 

Publicado: noviembre de 2016

Se aplica a: Dynamics CRM 2015

Puede crear una entidad que contenga una dirección de correo electrónico que pueda usar para enviar actividades de correo electrónico a los registros de la entidad.

El siguiente ejemplo crea una entidad personalizada y define la propiedad de IsActivityParty en true. También crea un atributo StringAttributeMetadata mediante StringFormatName.Email para proporcionar una dirección de correo electrónico que usar.

Incluso si agrega otros atributos StringAttributeMetadata con el formato de una dirección de correo electrónico, sólo se usa el primero especificado.



// Create the custom entity.
CreateEntityRequest createrequest = new CreateEntityRequest
{
    // Define an entity to enable for emailing. In order to do so,
    // IsActivityParty must be set.
    Entity = new EntityMetadata
    {
        SchemaName = _customEntityName,
        DisplayName = new Label("Agent", 1033),
        DisplayCollectionName = new Label("Agents", 1033),
        Description = new Label("Insurance Agents", 1033),
        OwnershipType = OwnershipTypes.UserOwned,
        IsActivity = false,

        // Unless this flag is set, this entity cannot be party to an
        // activity.
        IsActivityParty = true
    },

    // As with built-in emailable entities, the Primary Attribute will
    // be used in the activity party screens. Be sure to choose descriptive
    // attributes.
    PrimaryAttribute = new StringAttributeMetadata
    {
        SchemaName = "new_fullname",
        RequiredLevel = new AttributeRequiredLevelManagedProperty(AttributeRequiredLevel.None),
        MaxLength = 100,
        FormatName = StringFormatName.Text,
        DisplayName = new Label("Agent Name", 1033),
        Description = new Label("Agent Name", 1033)
    }
};

_serviceProxy.Execute(createrequest);
Console.WriteLine("The emailable entity has been created.");

// The entity will not be selectable as an activity party until its customizations
// have been published. Otherwise, the e-mail activity dialog cannot find
// a correct default view.
PublishAllXmlRequest publishRequest = new PublishAllXmlRequest();
_serviceProxy.Execute(publishRequest);

// Before any emails can be created for this entity, an Email attribute
// must be defined.
CreateAttributeRequest createFirstEmailAttributeRequest = new CreateAttributeRequest
{
    EntityName = _customEntityName,
    Attribute = new StringAttributeMetadata
    {
        SchemaName = "new_emailaddress",
        RequiredLevel = new AttributeRequiredLevelManagedProperty(AttributeRequiredLevel.None),
        MaxLength = 100,                            
        FormatName = StringFormatName.Email,
        DisplayName = new Label("Email Address", 1033),
        Description = new Label("Email Address", 1033)
    }
};

_serviceProxy.Execute(createFirstEmailAttributeRequest);
Console.WriteLine("An email attribute has been added to the emailable entity.");

// Create a second, alternate email address. Since there is already one 
// email attribute on the entity, this will never be used for emailing
// even if the first one is not populated.
CreateAttributeRequest createSecondEmailAttributeRequest = new CreateAttributeRequest
{
    EntityName = _customEntityName,
    Attribute = new StringAttributeMetadata
    {
        SchemaName = "new_secondaryaddress",
        RequiredLevel = new AttributeRequiredLevelManagedProperty(AttributeRequiredLevel.None),
        MaxLength = 100,                            
        FormatName = StringFormatName.Email,
        DisplayName = new Label("Secondary Email Address", 1033),
        Description = new Label("Secondary Email Address", 1033)
    }
};

_serviceProxy.Execute(createSecondEmailAttributeRequest);

Console.WriteLine("A second email attribute has been added to the emailable entity.");


' Create the custom entity.
Dim createrequest As CreateEntityRequest = New CreateEntityRequest With {.Entity = New EntityMetadata With {
  .SchemaName = _customEntityName,
  .DisplayName = New Label("Agent", 1033),
  .DisplayCollectionName = New Label("Agents", 1033),
  .Description = New Label("Insurance Agents", 1033),
  .OwnershipType = OwnershipTypes.UserOwned,
  .IsActivity = False, .IsActivityParty = True},
  .PrimaryAttribute = New StringAttributeMetadata With {
   .SchemaName = "new_fullname",
   .RequiredLevel = New AttributeRequiredLevelManagedProperty(AttributeRequiredLevel.None),
   .MaxLength = 100,
   .Format = StringFormat.Text,
   .DisplayName = New Label("Agent Name", 1033),
   .Description = New Label("Agent Name", 1033)
   }
  }
' Define an entity to enable for emailing. In order to do so,
' IsActivityParty must be set.
' Unless this flag is set, this entity cannot be party to an
' activity.
' As with built-in emailable entities, the Primary Attribute will
' be used in the activity party screens. Be sure to choose descriptive
' attributes.

_serviceProxy.Execute(createrequest)
Console.WriteLine("The emailable entity has been created.")

' The entity will not be selectable as an activity party until its customizations
' have been published. Otherwise, the e-mail activity dialog cannot find
' a correct default view.
Dim publishRequest As New PublishAllXmlRequest()
_serviceProxy.Execute(publishRequest)

' Before any emails can be created for this entity, an Email attribute
' must be defined.
Dim createFirstEmailAttributeRequest As CreateAttributeRequest = New CreateAttributeRequest With {
 .EntityName = _customEntityName,
 .Attribute = New StringAttributeMetadata With {
  .SchemaName = "new_emailaddress",
  .RequiredLevel = New AttributeRequiredLevelManagedProperty(AttributeRequiredLevel.None),
  .MaxLength = 100,
  .Format = StringFormat.Email,
  .DisplayName = New Label("Email Address", 1033),
  .Description = New Label("Email Address", 1033)
 }
}

_serviceProxy.Execute(createFirstEmailAttributeRequest)
Console.WriteLine("An email attribute has been added to the emailable entity.")

' Create a second, alternate email address. Since there is already one 
' email attribute on the entity, this will never be used for emailing
' even if the first one is not populated.
Dim createSecondEmailAttributeRequest As CreateAttributeRequest = New CreateAttributeRequest With {
 .EntityName = _customEntityName,
 .Attribute = New StringAttributeMetadata With {
  .SchemaName = "new_secondaryaddress",
  .RequiredLevel = New AttributeRequiredLevelManagedProperty(AttributeRequiredLevel.None),
  .MaxLength = 100,
  .Format = StringFormat.Email,
  .DisplayName = New Label("Secondary Email Address", 1033),
  .Description = New Label("Secondary Email Address", 1033)
 }
}

_serviceProxy.Execute(createSecondEmailAttributeRequest)

Console.WriteLine("A second email attribute has been added to the emailable entity.")

Ver también

Usar el ejemplo y el código auxiliar
Personalizar metadatos de entidad
¿Qué entidades se pueden personalizar?
Crear una entidad personalizada
Recuperar, actualizar y eliminar entidades
Crear una entidad de actividad personalizada
Modificar los iconos para una entidad
Modificar los mensajes de una entidad
Ejemplo: crear y actualizar una entidad que se puede enviar por correo electrónico

© 2017 Microsoft. Todos los derechos reservados. Copyright