AXForum  
Вернуться   AXForum > Microsoft Dynamics CRM > Dynamics CRM: Blogs
CRM
Забыли пароль?
Зарегистрироваться Правила Справка Пользователи Сообщения за день Поиск

 
 
Опции темы Поиск в этой теме Опции просмотра
Старый 17.02.2018, 02:14   #1  
Blog bot is offline
Blog bot
Участник
 
25,475 / 846 (79) +++++++
Регистрация: 28.10.2006
powerobjects: The New Auto Number Feature in Dynamics 365
Источник: https://www.powerobjects.com/2018/02...-dynamics-365/
==============


Auto numbers or unique alphanumeric strings are usually needed by CRM users to uniquely identify records in UI. We have developed plugins in the past, which would generate unique identifiers for us by using counters or random strings.

Microsoft has released an “Auto number” attribute in the 9.0 version of Dynamics 365. Adding the attribute from UI is not allowed yet, but it will be soon. Until then, we can add the attribute via API.

Let’s add one.

1. Create a console application in Visual Studio.



2. Add the Dynamics 365 V9.0 dlls as references. Currently, the preview version of the dlls is available in NuGet.

https://www.nuget.org/packages/Micro....0.0.4-Preview

3. Create a connection to your organization and call the CreateAutoNumberAttribute function from the Main() function.

using System;


using System.Collections.Generic;


using System.Linq;


using System.Text;


using System.Threading.Tasks;


using System.Configuration;


using Microsoft.Xrm.Sdk;


using Microsoft.Xrm.Sdk.Query;


using Microsoft.Xrm.Sdk.Client;


using Microsoft.Xrm.Sdk.Messages;


using Microsoft.Xrm.Sdk.Metadata;


using System.ServiceModel.Description;


static
void Main(string[] args)


{



string orgServiceUrl = ConfigurationManager.AppSettings[“orgServiceUrl”];



string userName = ConfigurationManager.AppSettings[“username”];



string password = ConfigurationManager.AppSettings[“password”];



Uri oUri = new
Uri(orgServiceUrl);



//** Your client credentials



ClientCredentials clientCredentials = new
ClientCredentials();


clientCredentials.UserName.UserName = userName;


clientCredentials.UserName.Password = password;



//Create your Organization Service Proxy



OrganizationServiceProxy _serviceProxy = new
OrganizationServiceProxy(


oUri,



null,


clientCredentials,



null);


CreateAutoNumberAttribute(“account”, “new_accountnumber”, _serviceProxy);


}

4. Following function creates an auto number attribute of “string” type in “Account” entity.

“AutoNumberFormat” is the new property that has been added to the AttributeMetadata class to help us add the auto number attribute.

public
static
void CreateAutoNumberAttribute(string entityName, string attributename, OrganizationServiceProxy _orgServiceProxy)


{



CreateAttributeRequest newAttributeReq = new
CreateAttributeRequest


{


EntityName = entityName.ToLower(),


Attribute = new
StringAttributeMetadata


{


AutoNumberFormat = “ACC-{RANDSTRING:6}”,


LogicalName = attributename.ToLower(),


SchemaName = attributename.ToLower(),


MaxLength = 150,


RequiredLevel = new
AttributeRequiredLevelManagedProperty(AttributeRequiredLevel.None),


FormatName = StringFormatName.Text,


DisplayName = new Microsoft.Xrm.Sdk.Label(“Account Number”, 1033),


Description = new Microsoft.Xrm.Sdk.Label(“Unique alphanumberic number for each account”, 1033)


}


};


_orgServiceProxy.Execute(newAttributeReq);


}


5. Time to check out the new attribute!



6. Let’s create few accounts and check the auto numbers!



7. 9.0 version of Dynamics 365 supports the following tokens for Auto numbers:

Static String
DATE:[format]
SEQNUM:size
RANDSTRING:6

There you have it! We’re happy to have this feature added to Dynamics 365. Be sure to check out our blog for more updates, news, and tips for Dynamics 365!

Happy Dynamics 365’ing!



Источник: https://www.powerobjects.com/2018/02...-dynamics-365/
__________________
Расскажите о новых и интересных блогах по Microsoft Dynamics, напишите личное сообщение администратору.
 

Похожие темы
Тема Автор Раздел Ответов Посл. сообщение
powerobjects: Dynamics 365 for Finance & Operations: Security Blog bot DAX Blogs 1 24.01.2018 12:45
powerobjects: How to Export a Theme from One Dynamics 365 Org to Another Blog bot Dynamics CRM: Blogs 0 16.12.2017 00:13
powerobjects: PowerObjects’ Top 10 Most Popular Blog Posts of 2017 Blog bot Dynamics CRM: Blogs 0 15.12.2017 03:21
powerobjects: Dynamics 365 for Retail: Inventory and Replenishment Blog bot DAX Blogs 0 06.12.2017 02:14
CRM DE LA CREME! Configuring Microsoft Dynamics CRM 4.0 for Internet-facing deployment Blog bot Dynamics CRM: Blogs 0 18.08.2009 11:05

Ваши права в разделе
Вы не можете создавать новые темы
Вы не можете отвечать в темах
Вы не можете прикреплять вложения
Вы не можете редактировать свои сообщения

BB коды Вкл.
Смайлы Вкл.
[IMG] код Вкл.
HTML код Выкл.
Быстрый переход

Рейтинг@Mail.ru
Часовой пояс GMT +3, время: 01:10.
Powered by vBulletin® v3.8.5. Перевод: zCarot
Контактная информация, Реклама.