viernes, 13 de septiembre de 2013

CRM 4.0 - Convertir una entidad dynamica en texto


This method returns the value of a dynamic entity attribute.


 /// <summary>
 /// This method returns the value of a dynamic entity attribute.
 /// </summary>
 private static object GetAttribute(BusinessEntity entity, string attribute) {
  if (entity.GetType() == typeof(DynamicEntity)) {
   DynamicEntity de = (DynamicEntity)entity;
   foreach (Property prop in de.Properties) {
    if (prop.Name == attribute) {
     PropertyInfo propInfo = prop.GetType().GetProperty("Value");
     return propInfo.GetValue(prop, null);
    }
   }
   return null;
  }
  else {
   PropertyInfo propInfo = entity.GetType().GetProperty(attribute);
   return propInfo.GetValue(entity.ToString(), null);
  }
 }

GetStringValue



 private static string GetStringValue(DynamicEntity entity, string atributo) {
  object resultado;
  resultado = GetAttribute(entity, atributo);
  if (resultado != null) {
   string tipo = resultado.GetType().ToString();
   tipo = tipo.Substring(tipo.LastIndexOf('.') + 1, tipo.Length - tipo.LastIndexOf('.') - 1);
   switch (tipo) {
    case "String":
     return (string)resultado;
    case "Picklist":
     return ((Picklist)resultado).name;
    case "Lookup":
     return ((Lookup)resultado).Value.ToString();
    case "Customer":
     return ((Customer)resultado).Value.ToString();
    case "Key":
     return ((Key)resultado).Value.ToString();
    case "CrmDateTime":
     return ((CrmDateTime)resultado).date;
    case "CrmBoolean":
     return ((CrmBoolean)resultado).name;
    case "CrmMoney":
     return ((CrmMoney)resultado).formattedvalue;

    case "CrmNumber":
     return ((CrmNumber)resultado).Value.ToString();
    case "Owner":
     return ((Owner)resultado).Value.ToString();
   }

  }
  return "sin valor";
 }

ConvertToXml


 private static string ConvertToXml(DynamicEntity entity) {
  StringBuilder xml = new StringBuilder();
  //  open root element
  xml.Append(string.Format("<{0}>\r\n", entity.Name));
  //  loop through properties and write out elements
  foreach (Property prop in entity.Properties) {
   string propName = prop.Name;
   //string propVal = entity.Properties[prop.Name].ToString();
   string propVal = GetStringValue(entity, propName);
   xml.Append(string.Format("<{0}>{1}</{0}>\r\n", propName, propVal));
  }
  //  close root element
  xml.Append(string.Format("</{0}>\r\n", entity.Name));
  //  return results
  return xml.ToString();
 }

CRM 4.0 - Trabajar con la entidad Notes de crm

------------------------------------------------------------

Annotation (Note) Entity Capabilities
To upload or remove an attachment, use the Update message, setting the filename and mimetype properties

------------------------------------------------------------

Create Use this message to create an annotation (note).
The information that is needed to create the entity instance is specified in the TargetCreateAnnotation class.
You can also call the Create method.

------------------------------------------------------------

Rollup Use this message to retrieve all the annotations (notes) related to the specified entity (account, contact, or opportunity).
The information that is needed to perform this action is specified in one of these classes:
TargetRollupAnnotationByAccount
TargetRollupAnnotationByContact
TargetRollupAnnotationByOpportunity

------------------------------------------------------------

CRM 4.0 - Modificación de vistas ocultas o no mediante urls

http://crmtoall.blogspot.com/2009/11/como-personalizar-todas-las-vistas-del.html


Los pasos a realizar son los siguientes:


1) Hacer una consulta SQL en la base de datos:


   Select SavedQueryId from savedquerybase  
   where name like '%Todos los integrantes%'  
   AND ReturnedTypeCode=2 


Una vez que tenemos el id, solamente tenemos que entrar a una URL pasandole dicho GUID y allí se podrá modificar la vista en cuestión:

http://servidor/empresa/tools/vieweditor/viewManager.aspx?id={2F0D0EDE-D356-4B1E-83BD-E978F10E3EEB}

CRM 4.0 - Sacar una select en sql para sacar lo que esta compartido y con quien

select systemuser.FullName as Usuario, PO.ObjectId as 'GUID Entidad', E.Name as 'Tipo de entidad' from PrincipalObjectAccess as PO
inner join MetadataSchema.Entity E on PO.ObjectTypeCode = E.ObjectTypeCode
inner join SystemUser on PO.PrincipalId = systemuser.SystemUserId
where AccessRightsMask <> 0
and Name <> 'ActivityPointer' and Name <> 'SystemUser' and Name <> 'UserSettings'
and PrincipalTypeCode = 8 and systemuser.FullName = @Usuario
order by Usuario, [Tipo de entidad]

CRM 4.0 - Sacar el permiso necesario en un error de permisos

select * from Privilege where PrivilegeId = 'a8bff87f-0df0-41d4-babd-f093faf1e32c'

select fullname from SystemUser where SystemUserId = '1728e69a-9192-df11-8359-005056895f40'

CRM 4.0 - Sacar el número de série del crm

select LicenseKey from ConfigSettings

CRM 4.0 - Saber la versión del crm que tienes

Ayuda -> Acerca de.

Version Build Number Released on
RTM 4.0.7333.3 12/19/2007
Update Rollup 1 4.0.7333.1113 11/24/2008
Update Rollup 2 4.0.7333.1312, 4.0.7333.1316 1/15/2009, 2/8/2009
Update Rollup 3 4.0.7333.1408 3/12/2009
Update Rollup 4 4.0.7333.1551 5/7/2009
Update Rollup 5 4.0.7333.1644, 4.0.7333.1645 7/2/2009
Update Rollup 6 4.0.7333.1750 9/27/2009
Update Rollup 7 4.0.7333.2138 10/22/2009
Update Rollup 8 4.0.7333.2542 12/17/2009
Update Rollup 9 4.0.7333.2644 02/11/2010
...