Friday, April 11, 2014

No Default Value on Two Options Field Dynamics CRM 2011

function setTwoOptionNull(twoOption) {
    var isCreateForm = Xrm.Page.ui.getFormType() == 1;
    var twoOptionField = Xrm.Page.getAttribute(twoOption);
    var twoOptionValue = twoOptionField.getValue();
    if (isCreateForm) {
        twoOptionField.setValue(null); // set the value to null on create
        twoOptionField.setSubmitMode("always"); // required to store the null value
        document.getElementById("rad_" + twoOption + "1").onclick = function () { 
            if (twoOptionValue == false) {
                twoOptionField.setValue(true);
                twoOptionField.setValue(false);
            }
        }
    }
}

pass the value "new_acceptreject" as shown below

Monday, April 7, 2014

Split the String in Microsoft Dynamics CRM using Javascript

Add the below function in the onload of the lead form

function getMonth()
{
debugger;
var Day=Xrm.Page.getAttribute("createdon").getValue().toString().substring(0,3);
alert(Day);
//you will get the output as Tue
}

Now open an existing lead record then the alert will show the Day of the lead createdon.

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(“Notification message”);  //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

Set field notification
Xrm.Page.getControl(fieldname).setNotification(“Notification message”);
Clear field notification
Xrm.Page.getControl(fieldname).clearNotification();
Set form notification
//First parameter is message, second is notification type, third is optional id parameter
Xrm.Page.ui.setFormNotification(‘Error! Message’,'ERROR’,’1′);
Xrm.Page.ui.setFormNotification(‘Warning!Message’,'WARNING’,’2′);
Xrm.Page.ui.setFormNotification(‘Information! Message’,'INFORMATION’,’3′);
Clear form notification
//Pass parameter id of notification which needs to be cleared
Xrm.Page.ui.clearFormNotification(’1′);

I noticed that currency field value on CRM forms were not accessible using Xrm.Page.getAttribute(“Currency field name”).getValue() and Xrm.Page.getAttribute(“Currency field name”).setValue(Value)
The resolution is in such cases is:
// 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);

Friday, March 28, 2014

Differences Between the SQL-based and Fetch-based Reports


Area
SQL-based Report
Data Provider
The <DataProvider> element value in the .rdl file is set to SQL. For example:
<DataProvider>SQL</DataProvider>
Report query
The query specified for retrieving data is in the <CommandText> sub-element under the<Query> element in the report definition (.rdl file) is a SQL query. For example, the query for retrieving all account names for a SQL-based report will be:
<CommandText>SELECT name FROM FilteredAccount;</CommandText>

Area
Fetch-based report
Data Provider
The <DataProvider> element value in the .rdl file is set to MSCRMFETCH. For example:
<DataProvider>MSCRMFETCH</DataProvider>
Report query
The query specified for retrieving data is in the <CommandText> sub-element under the <Query> 
element in the report definition (.rdl file) is a FetchXML query. For example, the query for retrieving
 all account names for a Fetch-based report will be:
<CommandText>&lt;fetch version="1.0" output-format="xml-platform" mapping="logical"&gt;
    &lt;entity name="account"&gt;
        &lt;attribute name="name" /&gt;
    &lt;/entity&gt;
&lt;/fetch&gt;</CommandText>

Tuesday, March 18, 2014

Get all the tables from the SQL database

SELECT TABLE_SCHEMA, TABLE_NAME, COLUMN_NAME, ORDINAL_POSITION, COLUMN_DEFAULT, DATA_TYPE, CHARACTER_MAXIMUM_LENGTH, 
NUMERIC_PRECISION, NUMERIC_PRECISION_RADIX, NUMERIC_SCALE, DATETIME_PRECISION FROM INFORMATION_SCHEMA.COLUMNS ORDER BY TABLE_NAME

Friday, January 31, 2014

Get the data from all the tables

USE AIRLINE --DB NAME
GO
DECLARE @COLUMNNAME AS VARCHAR(50) = 'PNAME' --THE NAME OF THE COLUMN ON WHICH YOU NEED TO PUT THE CRITERIA
DECLARE @CRITERIA AS VARCHAR(50) = 'CONVERT(DATE,' + @COLUMNNAME + ') >= ''20130225''' -- THE ACTUAL CRITERIA/WHERE CLAUSE OF THE QUERY

PRINT @COLUMNNAME
PRINT @CRITERIA

SELECT 
  'SELECT ''' + T.NAME + ''' AS  TABLENAME, * FROM ' + T.NAME + ' WHERE ' + @CRITERIA 
FROM 
  SYS.COLUMNS C
INNER JOIN SYS.TABLES T
  ON T.OBJECT_ID = C.OBJECT_ID   
WHERE 
  C.NAME = @COLUMNNAME

Last Execution Date Time of a Stored Procedure

USE Airline
GO

SELECT 
  O.NAME,
  PS.LAST_EXECUTION_TIME
FROM 
  SYS.DM_EXEC_PROCEDURE_STATS PS 
INNER JOIN SYS.OBJECTS O 
  ON O.[OBJECT_ID] = PS.[OBJECT_ID]