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

 
 
Опции темы Поиск в этой теме Опции просмотра
Старый 23.08.2011, 19:11   #1  
Blog bot is offline
Blog bot
Участник
 
25,626 / 848 (80) +++++++
Регистрация: 28.10.2006
Gareth Tucker: A Configuration Data Framework for CRM 2011
Источник: http://gtcrm.wordpress.com/2011/08/2...-for-crm-2011/
==============

In this post I describe a solution for managing and accessing configuration data required by client side extensions.  Imagine you have developed some jscript code that needs environment specific values such as the GUID of a specific view, workflow or dialog.  Here’s my approach using a custom entity and REST…

Here’s a scenario to provide some context.  In this post Rhett Clinton provides a jscript solution for defaulting a Customer Lookup to Contact rather than Account.

i.e. when you click on the Phone Number form’s “Sender” field the lookup that appears has “Look for” set to Contact rather than Account:



The line of code that does this is highlighted below:



The second line above is there to overcome a problem.  Without that 2nd line what you find is the lookup window switches to Contact but the default view in the lookup defers to whatever the default public view for the entity is – for Contact this is typically “My Active Contacts” – and this isn’t typically what we want.  

The second line of code changes the default view to “All Actives Contact” but a hardcoded value is being used.  For you to use this code you will need to determine the GUID of your “All Actives Contact” view (it will be different in each CRM installation) and change the code.   And this approach is no good if you are operating DEV and TEST environments (which you should be!) as the code will not transport without adjustment.

So here we have a good example of the need for configuration data that can be retrieved via CRM jscript.  Here’s my solution.

Firstly, the best place for this configuration data is CRM.  It’s an easy data store for us to query, it is fully securable and if required we can leverage CRM’s audit, field level security, and data import functionality.  Here’s my entity:



I have implemented a simple data model.  A record consists of an identifying name and then the configuration value.  The Value field is a multi-line text field which means it can support a simple single text field or numeric value or a more complicated XML value.

Now to utilise the configuration data we need a jscript function that can perform a REST query.   Here’s my function:

function GetConfigValue(ConfigParamName) {

//alert("GetConfigValue function begin, param value: " + ConfigParamName);

 

// Get the CRM URL

var serverUrl = Xrm.Page.context.getServerUrl();

 

// Cater for URL differences between on premise and online

if (serverUrl.match(/\/$/)) {

serverUrl = serverUrl.substring(0, serverUrl.length - 1);

}

 

// Specify the ODATA end point (this is the same for all CRM 2011 implementations)

var ODATA_ENDPOINT = "/XRMServices/2011/OrganizationData.svc";

 

// Specify the ODATA entity collection (this needs to be specific to your entity)

var ODATA_EntityCollection = "/new_configurationSet";

 

//var ConfigParamName = "ActiveContactsViewGUID";

 

// Specify the ODATA filter

var ODATA_Query = "?$select=new_Value&$filter=new_name%20eq%20\'" + ConfigParamName + "\'&$top=1";

 

// Build the URL

var ODATA_Final_url = serverUrl + ODATA_ENDPOINT + ODATA_EntityCollection + ODATA_Query;

 

//alert(ODATA_Final_url);

 

//Calls the REST endpoint

$.ajax({

type: "GET",

contentType: "application/json; charset=utf-8",

datatype: "json",

url: ODATA_Final_url,

 

beforeSend: function (XMLHttpRequest) {

//Specifying this header ensures that the results will be returned as JSON.

XMLHttpRequest.setRequestHeader("Accept", "application/json");

},

success: function (data, textStatus, XmlHttpRequest) {

//This function will trigger asynchronously if the Retrieve was successful

//alert("ajax call success");

//alert("Configuration parameter value: " + data.d.results[0].new_Value);

return (data.d.results[0].new_Value);

},

error: function (XmlHttpRequest, textStatus, errorThrown) {

//This function will trigger asynchronously if the Retrieve returned an error

//alert("ajax call failed");

}

});

}

 

 
To call the function from a CRM form you need to reference the web resource that contains this function and web resources that contain json and jquery libraries:

 

Then you can simply use this syntax to translate configuration parameter names into their respective values:

function ChangeLookup() {

document.getElementById("from").setAttribute("defaulttype", "2");

var ConfigValue = GetConfigValue("ActiveContactsViewGUID");

Xrm.Page.getControl("from").setDefaultView(ConfigValue);

}
The relevant piece there being…



… where I call the “GetConfigValue” function, passing in the configuration parameter name "ActiveContactsViewGUID" which returns the configuration value into the variable “ConfigValue”.

There you have it, a nice little configuration framework for your client side scripting.  Solution file containing the entity and web resource is available here.





Источник: http://gtcrm.wordpress.com/2011/08/2...-for-crm-2011/
__________________
Расскажите о новых и интересных блогах по Microsoft Dynamics, напишите личное сообщение администратору.
 

Похожие темы
Тема Автор Раздел Ответов Посл. сообщение
Gareth Tucker: Installing the Customer Care Accelerator (CCA) for CRM 2011 Blog bot Dynamics CRM: Blogs 3 23.12.2011 09:16
Gareth Tucker: CRM 2011 Command Line Installs – continued… Blog bot Dynamics CRM: Blogs 0 25.07.2011 10:11
Gareth Tucker: ‘Sharing’ Secured Fields in CRM 2011 Blog bot Dynamics CRM: Blogs 0 19.05.2011 23:13
Gareth Tucker: Getting Started with CRM 2011 Online Fetch XML Reporting Blog bot Dynamics CRM: Blogs 0 19.05.2011 23:13
при построении перекрёстных ссылок выдаётся сообщение об ошибках mmmax DAX: Программирование 10 21.01.2005 12:42
Опции темы Поиск в этой теме
Поиск в этой теме:

Расширенный поиск
Опции просмотра

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

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

Рейтинг@Mail.ru
Часовой пояс GMT +3, время: 03:50.