Спрашивающий
Создание счетчика и кнопки

Вопрос
-
Здравствуйте коллеги. Я только начинаю разбираться с CRM.
Я создал собственный объект. Назвал его корпоративный клиент, содержит поля типа ФИО, E-mail-а. Получилась усечённая копия – Обращение.
Вопросы:
1. Я хочу на поле разместить элемент – типа счётчик, который автоматически нумерует новых ”корпоративных клиентов”. Самостоятельно реализовать мне это не удалось.
2. Создать на форме кнопочку при нажатии, на которую будет, в соседнем поле ввода обновляться актуальное дата и время. Не в момент сохранения, ни при открытии а именно при нажатии на кнопочку.
Извиняюсь что в одной теме спрашиваю сразу два вопроса,
Заранее благодарен за ответ, если можно поподробнее.
Дмитрий
20 февраля 2008 г. 7:46
Все ответы
-
Code Snippet
using System;
using System.Diagnostics;
using System.IO;
using System.Xml;
using WorkingWithCrm.Callout.CrmSdk;
using WorkingWithCrm.Callout.MetadataServiceSdk;
using Microsoft.Crm.Callout;
namespace WorkingWithCrm.Callout
{
///
/// This Sample shows how to log various events with callouts
///
public class LeadCallout: CrmCalloutBase
{
public LeadCallout()
{
}// This Sample shows how to log an object creation using a precallout
public override PreCalloutReturnValue PreCreate(CalloutUserContext userContext, CalloutEntityContext entityContext, ref string entityXml, ref string errorMessage)
{
// Call the helper function NextLeadNumber() to return the next highest lead number value
string nextLeadNumber = NextLeadNumber();// Create an xml document in order to work with the xml stream
XmlDocument entityDoc = new XmlDocument();
entityDoc.LoadXml(entityXml);// Create the appropriate xml node
XmlNodeList propertyList = entityDoc.GetElementsByTagName("Property");
XmlElement leadNumberValue = null;
XmlElement properties = (XmlElement) entityDoc.GetElementsByTagName("Properties")[0];
XmlElement leadNumberElement = entityDoc.CreateElement("Property");
XmlAttribute typeAttrib = entityDoc.CreateAttribute("type");// Set the values for our new_leadnumber field
leadNumberElement.SetAttribute("type", "http://www.w3.org/2001/XMLSchema-instance", "StringProperty");
leadNumberElement.SetAttribute("Name", "new_leadnumber");
leadNumberValue = entityDoc.CreateElement("Value");
leadNumberValue.InnerText = NextLeadNumber();
leadNumberElement.AppendChild(leadNumberValue);
properties.AppendChild(leadNumberElement);// Add back to the entityXml
StringWriter output = new StringWriter();
entityDoc.Save(output);
entityXml = output.ToString();// Remove the extra XML that will confuse CRM
entityXml = entityXml.Replace("xmlns=\"\"", "");
entityXml = entityXml.Replace("", "");return PreCalloutReturnValue.Continue;
}#region Helpers
public bool IsTextIncluded( string InputString, string ValueToCheck )
{
return (InputString.IndexOf(ValueToCheck) > -1);
}public string NextLeadNumber()
{
// Standard CRM Service Setup
CrmService service = new CrmService();
service.Credentials = System.Net.CredentialCache.DefaultCredentials;// We need a user that has global read access to the lead record so that we
// have the absolute maximum lead number. If all roles have global read privileges to
// the read value of the Lead, then this wouldn't be necessary.
// For production, access this guid in a config file.
Guid callerid = new Guid("0686EE2A-FC46-DA11-B935-0003FF07CD51");
// Impersonate our global read user
service.CallerIdValue = new CallerId();
service.CallerIdValue.CallerGuid = callerid;
// Create a set of columns to return
ColumnSet cols = new ColumnSet();
cols.Attributes = new string [] {"leadid", "new_leadnumber"};// Set the order of the bring back the highest new_leadnumber value at the top
OrderExpression order = new OrderExpression();
order.AttributeName = "new_leadnumber";
order.OrderType = OrderType.Descending;// To improve performance, we will only pass back the top record
// This will return only 1 page with 1 record per page
PagingInfo pages = new PagingInfo();
pages.PageNumber = 1;
pages.Count = 1;// Create a query expression and set the query parameters
QueryExpression query = new QueryExpression();
query.EntityName = EntityName.lead.ToString();
query.ColumnSet = cols;
query.Orders = new OrderExpression[] {order};
query.PageInfo = pages;
// Retrieve the values from CRM
BusinessEntityCollection retrieved = service.RetrieveMultiple(query);string nextNumber = "1";
// Check to see if we have any records
if (retrieved.BusinessEntities.Length > 0)
{
// Cast to results lead object and only retrieve first record
lead results = (lead)retrieved.BusinessEntities[0];// Return the next value lead number. If there are records, but none have a number (the result will be null), so just pass back 1
nextNumber = (results.new_leadnumber != null) ? (results.new_leadnumber.Value + 1).ToString() : "1";
}return nextNumber;
}
#endregion
}
}После построения конструкции необходимо обновить файл callout.config.xml
Code Snippet<?xml version="1.0" encoding="utf-8" ?>
<callout.config version="2.0">
<callout entity="contact" event="PostUpdate">
<subscription assembly="WorkingWithCrm.Callout.dll" class="WorkingWithCrm.Callout.DataAudit">
<prevalue>@all</prevalue>
<postvalue>@all</postvalue>
</subscription>
</callout><callout entity="opportunity" event="PreSetState">
<subscription assembly="WorkingWithCrm.Callout.dll" class="WorkingWithCrm.Callout.ValidateOpportunity">
<prevalue>actualvalue</prevalue>
<prevalue>new_projectstartdate</prevalue>
<prevalue>statusreason</prevalue>
<prevalue>statuscode</prevalue>
</subscription>
</callout><callout entity="lead" event="PreCreate">
<subscription assembly="WorkingWithCrm.Callout.dll" class="WorkingWithCrm.Callout.LeadCallout"></subscription>
</callout>
</callout.config>13 марта 2008 г. 6:50