Monday, November 3, 2014

Business Process stage field: Dynamics CRM 2013 Javascript

Enable/Disable Business Process stage field:
Xrm.Page.getControl(‘header_process_fieldname’).setDisabled(false);  //Enabled
Xrm.Page.getControl(‘header_process_fieldname’).setDisabled(true);  //Disabled
Show/Hide Business Process stage field:
Xrm.Page.getControl(‘header_process_fieldname’).setVisible(true);  //Show
Xrm.Page.getControl(‘header_process_fieldname’).setDisabled(false);  //Hide
Get Value/ Set Value Business Process stage field:
Xrm.Page.getControl(‘header_process_fieldname’).getAttribute().setValue(value);  //Set Value
Xrm.Page.getControl(‘header_process_fieldname’).getAttribute().getValue();  //Get Value
Set and Remove Notification on Business Process stage field:
Xrm.Page.getControl(‘header_process_fieldname’).setNotification(“Notificationmessage”);  //Set Notification message
Xrm.Page.getControl(‘header_process_fieldname’).clearNotification(); // Clear Notification message
Set Required levels on Business Process stage field:
(Xrm.Page.getControl(‘header_process_fieldname).getAttribute()).setRequiredLevel(‘required’); //Required level
(Xrm.Page.getControl(‘header_process_fieldname).getAttribute()).setRequiredLevel(‘none’); //none level
(Xrm.Page.getControl(‘header_process_fieldname).getAttribute()).setRequiredLevel(‘recommended’); //Recommended level

Note: I have noticed this code will work when current stage field in business process on form is visible on UI.

Get/Set currency field values in JavaScript for Dynamics CRM

We Cannot use the below code to retrieve the currency field value
Xrm.Page.getAttribute(“Currency field name”).getValue() and Xrm.Page.getAttribute(“Currency field name”).setValue(Value)

The resolution is in such cases you can access currency fields in below manner:
// To get currency field
Xrm.Page.data.entity.attributes.get(“Currency field name”).getValue();
// To set currency field

Xrm.Page.data.entity.attributes.get(“Currency field name”).setValue(Value);

Tuesday, October 28, 2014

Xrm.Utility.openEntityForm for Dynamics CRM 2013/2011

Open a new account record using JavaScript
Xrm.Utility.openEntityForm(“account”);

Open an existing account record JavaScript
Xrm.Utility.openEntityForm(“account”,”A85C0252-DF8B-E111-997C-00155D8A8410″);

Open a new account record with a specific form and setting default values JavaScript
var parameters = {};
parameters["formid"] = “b053a39a-041a-4356-acef-ddf00182762b”;
parameters["name"] = “Test”;
parameters["telephone1"] = “(425) 555-1234″;

Xrm.Utility.openEntityForm(“account”, null, parameters);

Open a new record with setting form values for regardingobjectid will not work. So, in that case, the Workaround? Here we go:

Open Form Script

//set the parameters to pass to the new form
var parameters = {};
var Regarding = Xrm.Page.getAttribute(“regardingobjectid”).getValue();
parameters["parameter_regardingid"] = Regarding[0].id;
parameters["parameter_regardingname"] = Regarding[0].name;
parameters["parameter_regardingtype"] = Regarding[0].entityType;
//Open the new form
Xrm.Utility.openEntityForm(“appointment”,null,parameters);

onLoad Script for new form which needs to be opened:

// Get the Value of the Regarding through the Customer Parameters
var param=Xrm.Page.context.getQueryStringParameters();
var regardingId=param["parameter_regardingid"];
var regardingName=param["parameter_regardingname"];
var regardingType=param["parameter_regardingtype"];
//Populate the Regarding if there is one
if (regardingId != undefined)

  {Xrm.Page.getAttribute(“regardingobjectid”).setValue([{id:regardingId, name:regardingName, entityType:regardingType}]);}  

Tuesday, October 7, 2014

MIGRATION FROM CRM 4.0 TO DYNAMICS CRM 2013

Migration from CRM 4.0 to Dynamics CRM 2013 is not a single step procedure, but it is nevertheless not difficult either. The steps involved would be to first move to CRM 2011 and then progressively upgrade to Dynamics CRM 2013. There exists no direct upgrade option from CRM 4.0 to Dynamics CRM 2013.
When migrating from CRM 4.0 to Dynamics CRM 2011, there are no changes in customizations required, as CRM 2011 supports all CRM 4.0 javascripts, plugins and DLLs. Dynamics CRM 2013 does not support some CRM 4 DLLs, SDKs, javascrips and plugins. These are to be checked prior to start of migration process and disabled to ensure a successful migration. The Legacy feature check tool from Microsoft helps to check all customizations which are unsupported by Dynamics CRM 2013. The Legacy feature check tool can be obtained from here and this document provides more inputs on these customizations.
After running the legacy feature check tool and the plugins and javascript issues are dealt with, the migration process to Dynamics CRM 2013 from CRM 2011 can be started. The customizations from CRM 2011 are supported by Dynamics CRM 2013, hence only the CRM 4 plugins need to be re-written for CRM 2011. The other option is to remove all CRM 4.0 customizations, migrate it to CRM 2011, and then to Dynamics CRM 2013, following which the customizations can be implemented in Dynamics CRM 2013 itself.

A Broad Outline Of Steps To Be Followed Are

  1. Software requirements and support to be checked on the server
  2. Plugins, workflows and java scripts to be checked using legacy feature check tool
  3. Remove all CRM 4.0 customizations prior to start of migration to CRM 2011
  4. Enable customizations in CRM 2011 if required
  5. Continue migration to Dynamics CRM 2013
  6. Add all the removed customizations to Dynamics CRM 2013, if not added earlier to CRM 2011

Some Issues That We Faced

  • The database table field length differences affected usability after migration. This has to be checked as there are differences in allowed field lengths between CRM 4.0, CRM 2011 and Dynamics CRM 2013
  • CRM 4.0 web services API were not removed prior to migration to Dynamics CRM 2013 which disrupted the upgrade. This customization was required to be removed and re-implemented in Dynamics CRM 2013
When migrating from CRM 2011 to Dynamics CRM 2013, the server can not be rolled back to CRM 2011. And to proceed with the migration, there are predominantly two different methodologies to follow, based on availability of resources. For a detailed document on migration from CRM 2011 to Dynamics CRM 2013.
Reference Link: http://www.nalashaa.com/migration-crm-4-0-dynamics-crm-2013/ 

Tuesday, September 23, 2014

GridView textbox Navigation using Arrow(up/down) keys using Javascript in ASP.Net

 function GetTextBoxValues1(txt) {
//sai krishna for right arrow
//debugger;
if (window.event.keyCode == 39) {
    //var cnt = document.getElementById("GridView1").rows[0].cells.length;
    var gridView = document.getElementById("GridView1");
    for (var i = 1; i < gridView.rows.length - 1; i++) {
        if (txt == document.getElementById("GridView1_txtWeek1_" + (i - 1)).id) {
            document.getElementById("GridView1_txtweek2_" + (i - 1)).focus();
            return false;
        }
        if (txt == document.getElementById("GridView1_txtweek2_" + (i - 1)).id) {
            document.getElementById("GridView1_txtweek3_" + (i - 1)).focus();
            return false;
        }
        if (txt == document.getElementById("GridView1_txtweek3_" + (i - 1)).id) {
            document.getElementById("GridView1_txtweek4_" + (i - 1)).focus();
            return false;
        }
        if (txt == document.getElementById("GridView1_txtweek4_" + (i - 1)).id) {
            document.getElementById("GridView1_txtweek4_" + (i - 1)).focus();
            return false;
        }
                  
    }
}
//sai krishna for left arrow
//debugger;
if (window.event.keyCode == 37) {
    //var cnt = document.getElementById("GridView1").rows[0].cells.length;
    var gridView = document.getElementById("GridView1");
    for (var i = gridView.rows.length - 1; i >= 1 ; i--) {
        if (txt == document.getElementById("GridView1_txtWeek1_" + (i - 1)).id) {
            document.getElementById("GridView1_txtWeek1_" + (i-1)).focus();
            return false;
        }
        if (txt == document.getElementById("GridView1_txtweek2_" + (i - 1)).id) {
            document.getElementById("GridView1_txtWeek1_" + (i - 1)).focus();
            return false;
        }
        if (txt == document.getElementById("GridView1_txtweek3_" + (i - 1)).id) {
            document.getElementById("GridView1_txtweek2_" + (i - 1)).focus();
            return false;
        }
        if (txt == document.getElementById("GridView1_txtweek4_" + (i - 1)).id) {
            document.getElementById("GridView1_txtweek3_" + (i - 1)).focus();
            return false;
        }
    }
}
//sai krishna for down arrow
if (window.event.keyCode == 40) {
    var gridView = document.getElementById("GridView1");
    for (var i = 1; i < gridView.rows.length-1; i++) {
        if (txt == document.getElementById("GridView1_txtWeek1_" + (i - 1)).id)
        {
            document.getElementById("GridView1_txtWeek1_" + (i)).focus();
            return false;
        }
    }
    for (var i = 1; i < gridView.rows.length - 1; i++) {
        if (txt == document.getElementById("GridView1_txtweek2_" + (i - 1)).id) {
            document.getElementById("GridView1_txtweek2_" + (i)).focus();
            return false;
        }
    }
    for (var i = 1; i < gridView.rows.length - 1; i++) {
        if (txt == document.getElementById("GridView1_txtweek3_" + (i - 1)).id) {
            document.getElementById("GridView1_txtweek3_" + (i)).focus();
            return false;
        }
    }
    for (var i = 1; i < gridView.rows.length - 1; i++) {
        if (txt == document.getElementById("GridView1_txtweek4_" + (i - 1)).id) {
            document.getElementById("GridView1_txtweek4_" + (i)).focus();
            return false;
        }
    }
}
//sai krishna for UP arrow
if (window.event.keyCode == 38) {
    var gridView = document.getElementById("GridView1");
    for (var i = gridView.rows.length - 1; i > 1 ; i--) {
        if (txt == document.getElementById("GridView1_txtWeek1_" + (i - 1)).id) {
            document.getElementById("GridView1_txtWeek1_" + (i-2)).focus();
            return false;
        }
    }
    for (var i = gridView.rows.length - 1; i > 1 ; i--) {
        if (txt == document.getElementById("GridView1_txtweek2_" + (i - 1)).id) {
            document.getElementById("GridView1_txtweek2_" + (i - 2)).focus();
            return false;
        }
    }
    for (var i = gridView.rows.length - 1; i > 1 ; i--) {
        if (txt == document.getElementById("GridView1_txtweek3_" + (i - 1)).id) {
            document.getElementById("GridView1_txtweek3_" + (i - 2)).focus();
            return false;
        }
    }
    for (var i = gridView.rows.length - 1; i > 1 ; i--) {
        if (txt == document.getElementById("GridView1_txtweek4_" + (i - 1)).id) {
            document.getElementById("GridView1_txtweek4_" + (i - 2)).focus();
            return false;
        }
    }
}
}

<asp:GridView ID="GridView1" TabIndex="0" runat="server" Width="100%" GridLines="Horizontal">
  <Columns>
    <asp:TemplateField HeaderText="Week" ItemStyle-HorizontalAlign="Center" HeaderStyle-CssClass="datagridheaders" HeaderStyle-ForeColor="white">
    <ItemTemplate>
  <asp:TextBox ID="txtweek2" runat="server" Width="75px" onkeyup="return GetTextBoxValues1(this.id);" Columns="10"></asp:TextBox>
  </ItemTemplate>
  </asp:TemplateField>
 </Columns>
</asp:GridView>

Thursday, September 11, 2014

Search for a specific text in entire database

USE [AIRLINES]
GO

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROC [dbo].[SearchTables]
(
     @SearchStr nvarchar(100)
)
AS
BEGIN

DECLARE @Results TABLE(ColumnName nvarchar(370), ColumnValue nvarchar(3630))
SET NOCOUNT ON
DECLARE @TableName nvarchar(256), @ColumnName nvarchar(128), @SearchStr2
nvarchar(110)
SET  @TableName = ''
SET @SearchStr2 = QUOTENAME('%' + @SearchStr + '%','''')

WHILE @TableName IS NOT NULL
BEGIN
     SET @ColumnName = ''
     SET @TableName =
     (
         SELECT MIN(QUOTENAME(TABLE_SCHEMA) + '.' + QUOTENAME(TABLE_NAME))
         FROM    INFORMATION_SCHEMA.TABLES
         WHERE       TABLE_TYPE = 'BASE TABLE'
             AND QUOTENAME(TABLE_SCHEMA) + '.' + QUOTENAME(TABLE_NAME) > @TableName
             AND OBJECTPROPERTY(
                     OBJECT_ID(
                         QUOTENAME(TABLE_SCHEMA) + '.' +
QUOTENAME(TABLE_NAME)
                          ), 'IsMSShipped'
                            ) = 0
     )
     WHILE (@TableName IS NOT NULL) AND (@ColumnName IS NOT NULL)
     BEGIN
         SET @ColumnName =
         (
             SELECT MIN(QUOTENAME(COLUMN_NAME))
             FROM    INFORMATION_SCHEMA.COLUMNS
             WHERE       TABLE_SCHEMA    = PARSENAME(@TableName, 2)
                 AND TABLE_NAME  = PARSENAME(@TableName, 1)
                 AND DATA_TYPE IN ('char', 'varchar', 'nchar', 'nvarchar')
                 AND QUOTENAME(COLUMN_NAME) > @ColumnName
         )
         IF @ColumnName IS NOT NULL
         BEGIN
             INSERT INTO @Results
             EXEC
             (
                 'SELECT ''' + @TableName + '.' + @ColumnName + ''', LEFT(' + @ColumnName + ', 3630)
                 FROM ' + @TableName + ' (NOLOCK) ' +
                 ' WHERE ' + @ColumnName + ' LIKE ' + @SearchStr2
             )
         END
     END
END
SELECT ColumnName, ColumnValue FROM @Results END

--To execute the above Stored Procedure
DECLARE @return_value int
EXEC @return_value = [dbo].[SearchTables]
@SearchStr = N'SAIKRISHNA'
SELECT 'Return Value' = @return_value