Search This Blog

Thursday, December 22, 2016

Plugin Message in Dynamics CRM

Plugin Message in Dynamics CRM




Message

Description

Create

This message will trigger when-ever primary entity record is created

Update

This message will trigger when-ever primary entity record is updated

Retrieve

This message will trigger when-ever primary entity record is retrieve( entity form open).

Eg: In the Active account grid, double click any one of the record this message will trigger.

Retrieve Multiple

This message will trigger when-ever primary entity records are viewed from grid.

Publish All customization

This message will trigger when-ever you click "PublishAll"

Publish

This message will trigger when-ever you click "Publish" on webresource and entity form.

Grant Access

This message will trigger when-ever record is shared 

Revoke Access

This message will trigger when-ever record is unshared

AddMember
This message will trigger and primary entity is "list" when-ever add member in the marketing  list through UI.

RemoveMember

This message will trigger and primary entity is "list"  
when-ever remove/delete member in the marketing
  list through UI.

AddListMember

This message will trigger and primary entity is "list" when-ever add member in the marketing  list through AddListMembersListRequest class(console application.

AddItem

This message will trigger whenever you add marketing list in the campaign activity
Remove Item

This message will trigger whenever you add marketing list in the campaign activity







Thursday, December 15, 2016

Convert OptionSet to MultiSelect checkboxes in CRM


  • Create two fields to store optionset value and text
  • Create html webresource with below source code.

<html>
<head>
    <title></title>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
    <script type="text/javascript">

        $(document).ready(function () {
            ConvertDropDownToCheckBox();
        });

        //Coverts option list to checkbox
        function ConvertDropDownToCheckBox() {

            var _optionSet = parent.Xrm.Page.getAttribute("new_optionSet").getOptions();
            var _optionSetValue = parent.Xrm.Page.getAttribute("address1_line1").getValue();

            $(_optionSet).each(function (i, e) {

                var _text = $(this)[0].text;
                var _value = $(this)[0].value;
                var _isChecked = false;
                if (_text !== '') {
                    if (_optionSetValue !== null && _optionSetValue.indexOf(_value) !== -1)
                        _isChecked = true;

                    var _checkbox = "<input type='checkbox' name='" + _value + "'/>";
                    $(_checkbox)
                        .attr("value", _value)
                        .attr("checked", _isChecked)
                        .attr("id", "id" + _value)
                        .click(function () {

                            //To Set Picklist Select Values
                            var selectedOption = parent.Xrm.Page.getAttribute("address1_line1").getValue();
                            if (this.checked) {
                                if (selectedOption === null)
                                    selectedOption = _value;
                                else {
                                    var temp = selectedOption.indexOf(",") !== -1 ? selectedOption.split(',') : selectedOption.split(' ');
                                    temp.push(_value);
                                    selectedOption = temp.join();
                                }
                            }
                            else {
                                if (selectedOption.indexOf(_value) !== -1) {
                                    var temp = selectedOption.indexOf(",") !== -1 ? selectedOption.split(',') : selectedOption.split(' ');
                                    temp = removeArrayElement(temp, _value);
                                    selectedOption = temp.join();
                                }
                                else
                                    selectedOption = selectedOption.replace(_value, "");
                            }
                            parent.Xrm.Page.getAttribute("address1_line1").setValue(selectedOption.toString());


                            //To Set Picklist Select Text
                            var _selectedText = parent.Xrm.Page.getAttribute("address1_line2").getValue();
                            if (this.checked) {
                                if (_selectedText === null)
                                    _selectedText = _text;
                                else {
                                    var temp = _selectedText.indexOf(',') !== -1 ? _selectedText.split(',') : _selectedText.split(' ');
                                    temp.push(_text);
                                    _selectedText = temp.join();
                                }
                            }
                            else {
                                if (_selectedText.indexOf(_text) != -1) {
                                    var temp = _selectedText.indexOf(',') !== -1 ? _selectedText.split(',') : _selectedText.split(' ');
                                    temp = removeArrayElement(temp, _text);
                                    _selectedText = temp.join();
                                }
                                else
                                    _selectedText = _selectedText.replace(_text, "");
                            }
                            parent.Xrm.Page.getAttribute("address1_line2").setValue(_selectedText);

                        }).appendTo(checkBoxContainer);
                }


                //add label to the checkbox
                $("<label for='" + _value + "'>" + _text + "</label>").appendTo(checkBoxContainer);
            });
        }


        function removeArrayElement(arr) {
            var what, a = arguments, L = a.length, ax;
            while (L > 1 && arr.length) {
                what = a[--L];
                while ((ax = arr.indexOf(what.toString())) != -1) {
                    arr.splice(ax, 1);
                }
            }
            return arr;
        }

    </script>
</head>
<body>

    <div id="checkBoxContainer">
    </div>

</body>
</html>

Please refer
https://community.dynamics.com/crm/f/117/t/211615

Show only date in SSES executiondatetime

In the SSRS report Expression column
Format(Globals!ExecutionTime, "MM/dd/YYYY")

Pass parameters to Plugin Using Secure or Unsecure Configuration Using Plugin Registration Tool in MS CRM

Pass parameters to Plugin Using Secure or Unsecure Configuration to Plugin:
When you start developing plugins, you often need an input parameter or a configuration for the plugin execution which can be easily updated without having to re-compile and/or re-register the plugin.
For example , i want to read some of the data which may change every time. Rather than creating the custom entity to read the Configuration kind of thing better to use this method to read the Parameters.
Use the plugin step “Configuration”
When you register a plugin step, there is a field where you can specify some configuration parameters for the plugin execution as below:Image
Then in the Constructor of your plugin class you will get the configuration value which you can use later in the Execute method:
Image2

In the Quickwatch you can watch the total configuration as follows:
Image1

have a glance below for plugin code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xrm.Sdk;
using System.Xml;
namespace ReadPluginConfgInPlugins
{
public class PluginConfg : IPlugin
{
private readonly string _unsecureString;
private readonly string _secureString;
public PluginConfg(string unsecureString, string secureString)
{
if (String.IsNullOrWhiteSpace(unsecureString) || String.IsNullOrWhiteSpace(secureString))
{
try
{
XmlDocument doc = new XmlDocument();
doc.LoadXml(unsecureString);
Guid DefaultQueueGuid = PluginConfiguration.GetConfigDataGuid(doc, “Contact Guid”);
string ContactFullName = PluginConfiguration.GetConfigDataString(doc, “Full Name”);
int MobileNumber = PluginConfiguration.GetConfigDataInt(doc, “Mobile Number”);
bool Gender = PluginConfiguration.GetConfigDataBool(doc, “Gender 0 refer to Male”);
}
catch (Exception ex)
{
throw new Exception(“SoapException” + ex.Message + “########” + ex.StackTrace + “$$$$Inner Exception” + ex.InnerException);
}
}
}
public void Execute(IServiceProvider serviceProvider)
{
//Extract the tracing service for use in debugging sandboxed plug-ins.
ITracingService tracingService =
(ITracingService)serviceProvider.GetService(typeof(ITracingService));
// Obtain the execution context from the service provider.
IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
// For this sample, execute the plug-in code only while the client is online.
tracingService.Trace(“AdvancedPlugin: Verifying the client is not offline.”);
if (context.IsExecutingOffline || context.IsOfflinePlayback)
return;
// The InputParameters collection contains all the data passed
// in the message request.
if (context.InputParameters.Contains(“Target”) &&
context.InputParameters[“Target”] is Entity)
{
Entity entity = (Entity)context.InputParameters[“Target”];
}
}
}
}
For this approach also have a Pros and Cons.
PROS:
  • The step configuration is solution-aware so it will be automatically transported with the plugin step.
CONS:
  • You need to use the plugin registration tool or another application to update the step configuration.
  • The configuration is step-specific so you have to provide it and/or update it for every step even if the value is the same for all the steps (the configuration is on each step instead of the assembly or plugin type).
  • the configuration is just an attribute of the plugin step so you cannot control privileges on the configuration independently from privileges on plugin step entity.
*. Use the plugin step “Secure Configuration”
This is similar to the step Configuration except that the configuration data is stored in a separate entity which can be secured.
PROS:
  • The configuration data can be secured as any other entity using the CRM security model. This is useful when the configuration contains sensitive information such as passwords.
CONS:
  • Secure configuration is not solution aware so you will need to configure it for each environment.
  • You need to use the plugin registration tool or another application to update the step configuration.
  • The configuration is step-specific so you have to provide it and/or update it for every step even if the value is the same for all the steps (the configuration is on each step instead of the assembly or plugin type).
*. Use a Web Resource
You can store configuration information in web resources, for example you might have some XML configuration stored in a web resource and have your plugin read the web resource each time it executes.
PROS:
  • Web resources are solution aware and the GUID is preserved across environments so you can hardcode the web resource GUID in your plugin code. You can transport the web resource and the plugin in the same solution.
  • Can be easily updated using the CRM UI.
CONS:
  • You cannot secure the configuration since it depends on the web resource access privileges and most users will need at least read access to web resources.
Hope this may help you.

Thanks to the below site
https://srmscrm.wordpress.com/category/ms-crm-2011/ms-crm-2011-plugins/

Lookup Control value set in CRM using Javascript

Lookup Control value set in CRM using Javascript

  var objPaymentModeValue = [{
        id: result[0].new_PaymentModeId.Id,
        name: result[0].new_PaymentModeId.Name,
        entityType: 'new_paymentmode'
    }];

 Xrm.Page.getAttribute("new_paymentmodeid").setValue(objPaymentModeValue);

Retrieve more than 5000 record in Query expression or Limit number of result record in query expression

 https://msdn.microsoft.com/en-us/library/gg327917.aspx


// Query using the paging cookie.
// Define the paging attributes.
// The number of records per page to retrieve.
int queryCount = 3;

// Initialize the page number.
int pageNumber = 1;

// Initialize the number of records.
int recordCount = 0;

// Define the condition expression for retrieving records.
ConditionExpression pagecondition = new ConditionExpression();
pagecondition.AttributeName = "parentaccountid";
pagecondition.Operator = ConditionOperator.Equal;
pagecondition.Values.Add(_parentAccountId);

// Define the order expression to retrieve the records.
OrderExpression order = new OrderExpression();
order.AttributeName = "name";
order.OrderType = OrderType.Ascending;

// Create the query expression and add condition.
QueryExpression pagequery = new QueryExpression();
pagequery.EntityName = "account";
pagequery.Criteria.AddCondition(pagecondition);
pagequery.Orders.Add(order);
pagequery.ColumnSet.AddColumns("name", "emailaddress1");                   

// Assign the pageinfo properties to the query expression.
pagequery.PageInfo = new PagingInfo();
pagequery.PageInfo.Count = queryCount;
pagequery.PageInfo.PageNumber = pageNumber;

// The current paging cookie. When retrieving the first page, 
// pagingCookie should be null.
pagequery.PageInfo.PagingCookie = null;
Console.WriteLine("Retrieving sample account records in pages...\n");
Console.WriteLine("#\tAccount Name\t\tEmail Address"); 

while (true)
{
    // Retrieve the page.
    EntityCollection results = _serviceProxy.RetrieveMultiple(pagequery);
    if (results.Entities != null)
    {
        // Retrieve all records from the result set.
        foreach (Account acct in results.Entities)
        {
            Console.WriteLine("{0}.\t{1}\t{2}", ++recordCount, acct.Name,
                               acct.EMailAddress1);
        }
    }

    // Check for more records, if it returns true.
    if (results.MoreRecords)
    {
        Console.WriteLine("\n****************\nPage number {0}\n****************", pagequery.PageInfo.PageNumber);
        Console.WriteLine("#\tAccount Name\t\tEmail Address");

        // Increment the page number to retrieve the next page.
        pagequery.PageInfo.PageNumber++;

        // Set the paging cookie to the paging cookie returned from current results.
        pagequery.PageInfo.PagingCookie = results.PagingCookie;
    }
    else
    {
        // If no more records are in the result nodes, exit the loop.
        break;
    }
}

CRM Form Load Performance

CRM Form Load Performance
Open the CRM on-premises and online in internet explorer.Click ctrl+shift+e

Send Mail when error occur in Scribe tool

Send Mail when error occur in Scribe tool

In scribe we have to alert recipents

Alert Recipients provide a means to notify users of alerts. Groups are formed from a stored list of individuals, each with an email address. Monitors and Integration Processes may be configured to notify a specific group and provide information on system status, data states, or business activity.


Adding alert recipient

Configure the email address

Create alert group and add recipients to group

Assigning a Recipient group in Monitor’s alert criteria






Append vs Append To

Append and Append To basically deal with the entities that are parties to a 1:N relationship or N:1 relationship.

Append: When an entity has the lookup of another entity on its form. It is important that the user have the “Append” privilege on this entity so that it can set the values for the lookups on this entity. For eg: Contact has the lookup of Account on its form so here the user needs to have the “Append” privilege to be able to set the parent account.

Append To: When an entity is available as a lookup on another entity form. It is important that the user have the “Append to” privilege on the entity that is referred to in the lookup so that it can set the values for the lookups of this entity on any other form. For eg: Account has the lookup of primary contact. So here the user needs to have the “Append To” privilege to be able to set the Primary Contact for the Account.

Report Server Folder Location

Native mode report server:
C:\Program Files\Microsoft SQL Server\MSRS12.MSSQLSERVER\Reporting Services\ReportServer
Sharepoint mode report server:
C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\WebServices\Reporting
Please look into below site:
https://msdn.microsoft.com/en-us/library/ms157273.aspx

CRM Plugin Message Export,ExportAll,ExportCompressed,ExportCompressedAll fire in plugin


1. Connect to SQL Server where CRM DB is located.
2. Open SQL Management Studio, open new query with context of your CRM DB (CRM_MSCRM or other name).
3. Execute following T-SQL Script:
Update SdkMessageFilter
Set IsCustomProcessingStepAllowed = 1
Where SdkMessageId in (Select distinct SdkMessageId From sdkmessage where name = 'ExportSolution')
4. Make IISReset.

5. Restart plugin registration tool - ExportSolution should be available for handling with plugins.