Friday, May 17, 2013

Drag and Drop file using Control Add-Ins in Microsoft Dynamics NAV


Control add-ins for the Microsoft Dynamics NAV are built with the Microsoft .NET Framework–based assemblies that you install on computers that are running the Microsoft Dynamics NAV Windows client.        

To include a control add-in on a Role Center, you apply the control add-in on a page that is assigned to a part of the Role Center. Control add-ins are not supported by the Microsoft Dynamics NAV Web client or Microsoft Dynamics NAV Portal Framework for Microsoft SharePoint 2010

Here we will see an example of Drag and Drop a file in the text box controls. On drag and drop the text box will provide you the path of the file with the filename and extension.

Follow the below procedure for Drag and Drop a file:
    1.       Open Visual Studio.
    2.       Select C# class library and provide the name for the solution. Here we have given name as DragDrop.
    3.       A New Class file will open.
    4.       Add the following references:
  • System.Drawing
  • System.Windows.Forms
  •  Microsoft.Dynamics.Framework.UI.Extensibilty.dll, by default, it is available in Program Files\Microsoft Dynamics NAV\60\RoleTailored Client folder.
   5.   Type the below code

using System.Drawing;

using System.Windows.Forms;

using Microsoft.Dynamics.Framework.UI.Extensibility;

using Microsoft.Dynamics.Framework.UI.Extensibility.WinForms;

using System.IO;

 

namespace DragDrop

{
    [ControlAddInExport ("DragandDrop3.5")]
    public class DraGDroP:WinFormsControlAddInBase

    {

        TextBox txt;

        protected override Control CreateControl()

        {

            txt = new TextBox();

            txt.MinimumSize = new Size(50, 0);

            txt.MaximumSize = new Size(500, Int32.MaxValue);

            txt.DragEnter += new DragEventHandler(txt_DragEnter);

            txt.DragDrop += new DragEventHandler(txt_DragDrop);

            txt.AllowDrop = true;

            return txt;

            throw new NotImplementedException();

        }

        private void txt_DragEnter(Object Sender, DragEventArgs e)

        {

            if(e.Data.GetDataPresent(DataFormats.FileDrop,false))

            {

                e.Effect =DragDropEffects.All;

            }

        }

        private void txt_DragDrop(Object sender, DragEventArgs e)

        {

            try

            {

                int index = 0;

                string data;

                string[] filecollection =(string[])e.Data.GetData(DataFormats.FileDrop );

                foreach (string file in filecollection )

                {

                    //this.txt.Text = Path.GetFileName (file);

                    this.txt.Text = Path.GetFullPath(file);

                    }

                data=this.txt.Text;

            }

            catch (Exception ex)

            {

            }

        }

    }

}
 
 
  6.    Now we need to Sign the Add-In assembly
  7.       Go to Project propertiesàsigning.
  8.       Select the checkbox “Sign the assembly”. Now choose a String Name key.
  9.       Click New. Specify the name and protect your assembly with Password.
  10.   Save and Build the Solution.
  11.   Copy the assembly dll from the folder you have saved. By Default, C:\My Documents\Visual Studio\Projects\[Addin Project name]\bin\Debug.
  12.   Paste the dll in the Add-Ins folder of the Role Tailored client. By default, C:\Program Files\Microsoft Dynamics NAV\60\RoleTailored Client\Add-ins.
  13.   Now we need to create a Public Key token.
  14.   Follow the link for creating public key token. http://msdn.microsoft.com/en-in/library/dd983825.aspx
  15.   Copy the Public key token created.
  16.    Now Open table Client add-in(2000000069) in Dynamics NAV.
  17.   Type the Control Add-in name as “DragandDrop3.5”.
 18.   Paste the copied Public Key.
  19.   Now Exit from the table.
  20.   Create a New Page in Page Designer. Like Below image.
 
 
21.   Go to the Control Add –in Property of a Field “Drag a File and Drop” and Choose the Public key token that created for this add-in.
22.   Save, Compile and Run the Page.
23.   Now drag a file from any of your folder and place in the text box.
24.   Refer the below image
 
Hope this helps in dragging a file and retrieving its full path by dropping the file.

Thursday, May 16, 2013

Resolving “Could not load Microsoft.IdentityModel” MS CRM 2011 service authentication error in windows 8

Most often when CRM development is carried out in new machine or in updated OS, the system pops out with CRM authentication service issue as displayed in below screen. Since the system is not yet configured with the “Windows Identity Foundation”.



To enable and to fix the issue, either of the follwing solution can be followed.

Solution 1:
Go to “Control Panel“>> “Programs and Features” >> in the left navigation pane click “Turn Windows features on or off” then select the “Windows Identity Foundation” and click “OK”.

Solution 2:
Go to “My Computer” and search the assembly name called “Microsoft.IdentityModel”. If the machine finds the library, then copy the dll and pasted it into the corresponding framework version folder under “C:\Program Files\Reference Assemblies\Microsoft\Framework”. Add this assembly as a reference in the visual studio application.


Hope this helps!



Friday, May 10, 2013

Adding Smartlist report to Dynamics GP Reminder


In Dynamics GP, we can easily create a remainder using standard and custom smartlist. The following steps clearly illustrates about the creation of custom smartlist reminder in Dynamics GP.

Steps to create Smartlist reminder:

1. Go to Microsoft Dynamics GP à Smartlist to open any smartlist report.
2. Click Favorites to open Add or Remove Favorites.
3. Enter the Smartlist name in name field (Ex: Customers Over Credit Limit)


4. Click Add favorite and reminder to open Custom Reminder window and select the Remind me when   condition based on the requirement. Click OK to set the reminder.


5. Go to Microsoft Dynamics GP àReminders, to find our custom smartlist report.


6. Check the GP Home page to view the custom Smartlist reminder.


7. The details of the reminder can be viewed through smartlist by clicking the reminder (Customer over Credit Limit).



Hope this helps!!!

Dynamics SL – Password protection for the Approval & Inquiry screens of Project Series

Password Maintenance (PA.PWD.00)
 (Open SL -> Project-> Project Controller-> Maintenance -> Password Maintenance)

Password Maintenance provides the entry and maintenance of security passwords, which are prompted for in certain screens. Specific key values, such as company ID, Employee ID, and subaccount, trigger prompting for a password in selected inquiry and approval screens throughout the system, particularly in review and approval screens. This screen is used to associate the key value with its corresponding password.

Field descriptions for Password Maintenance Screen given below.
1.      Password Type:
PV lookup in Password Type Valid password types are CPNY for company passwords, EMP for employee passwords, and ORG for organizational (subaccount) passwords. 
2.      Key Value:
Enter the secured key value to be password protected. For example, if the password type is EMP, enter the Employee ID to password-protect in the secured screens.
3.      Password:
Passwords can contain from 6 to 22 characters. They can include both upper- and lowercase letters in addition to numerals and special characters such as punctuation. When users enter their password on a secured screen, the characters in the password do not appear.

  Security reasons, it is important that this screen be restricted from unauthorized use.
Time Review and Approval Screen (TM.TRA.00)
  Open SL -> Project-> Time & Expense for Projects-> Processes -> Time Review and Approval
  • Select the Employee id with the password setup.
  • Enter Password window pops up prompting the user to enter the password.
Project inquiry (UZ.UPI.00)
  Open SL -> Project-> Employee Utilization-> inquiries -> Project inquiry
  • Select the Employee id with the password setup.
  • Enter Password window pops up prompting the user to enter the password.



Hope this helps!!


Updating an existing worksheet in Microsoft Dynamics NAV

In our last week’s blog we went through the process of generating a report into a new excel file. Click here to view on how to print reports in excel
The article below will show us on how to export values into an existing worksheet/workbook. This case is mostly applicable in scenarios where we don’t want to create new files every time when we generate a report.
The following scenario explains us where we already have a worksheet and we need to use the same excel workbook and use the worksheet that was previously used
A Sample image below indicates the existing excel book with existing sheet has some values:

How can we achieve this?
1.       Open the excel file by specifying the file path.
2.       Specify the excel sheet name.
3.       Clear the already existing contents.
4.       Export the values in the same worksheet
The following code drives the above steps:
//xlapp – Automation – Microsoft Excel 12.0 Object Library. Application
//xlbook – Automation – Microsoft Excel 12.0 Object Library. Workbook
//xlsheet – Automation – Microsoft Excel 12.0 Object Library. WorkSheet
//filepath – Text [1024]
 
Filepath:=’<Your Filepath>’; //Specify the location where the excel file is stored locally
IF ISCLEAR(xlapp) THEN
  CREATE(xlapp);
 
xlapp.visible(true);
 
//1. Opening the excel file
xlbook:=xlapp.Workbooks.Open(filepath);//specify your file path with the filename.xls(x)
 
xlbook:=xlapp.ActiveWorkbook;
 
//2. Specify the excel sheet name
xlsheet := xlbook.Worksheets.Item(‘<your Work Sheet Name>’);
 xlsheet.Activate();
 
//the below code will be useful when the excel sheet is already filtered based on some condition
// if it is filtered then we need to show all the data in the excel sheet.
 IF xlsheet.FilterMode THEN
    xlsheet.ShowAllData;
 
//3. Clearing the existing contents within worksheet
 xlsheet.Range(‘A1:C1048576’).ClearContents;
// Note: In this scenario we have specified C because we have only 3 columns and 1048576 denotes the max no of rows in excel 2007 and later
 
//4. Exporting the new values
xlsheet.Range(‘A1’).value:=’No.’; //1st Column Name
xlsheet.Range(‘B1’).value:=’Customer No; //2nd column Name
xlsheet.Range(‘C1’).value:=’Sales Person Code’; //3rd Column Name
 
//Exporting the sales header values
reccount:=2;   //where variable reccount - Integer
salesheader.RESET;  //where variable salesheadaer - Record - Sales Header var
IF salesheader.FINDSET THEN
REPEAT
  xlsheet.Range('A'+FORMAT(reccount)).Value:=salesheader."No.";
  xlsheet.Range('B'+FORMAT(reccount)).Value:=salesheader."Sell-to Customer No.";
  xlsheet.Range('C'+FORMAT(reccount)).Value:=salesheader."Salesperson Code";
  reccount:=reccount+1;
UNTIL salesheader.NEXT=0;
 
Xlbook.save;
 
After executing the code, the existing excel file will be opened automatically so that we can view the excel sheet with new/replaced values. The below image refers the values exported from a Sales Header table.
 
 

Thursday, May 9, 2013

Retrieve Linked Entity Data using Query Expression using MS CRM 2011 SDK


Most often you need to retrieve data from primary and related entity. This data can be retrieved using CRM SDK either with FetchXML or Query Expression.  In this blog, QueryExpression is used to retrieve primary and related entity data with a single database retrieve.
Below is the syntax of how related entity columns are retrieved.

Query Syntax:-

Parent Entity:-
var query = new QueryExpression(Entityname);
var columnNames = new[] { Columns to be Added };
query.ColumnSet = new ColumnSet(columnNames);

Linked Entity:-
var colsAccount = new[] { LinkEntity Columns to be Added }; // Related Entity Fields
LinkEntity linkentity = new LinkEntity() {
LinkFromEntityName = EntityName,
LinkFromAttributeName = EntityFieldName,
LinkToEntityName = LinkEntityName,
LinkToAttributeName = LinkEntityFieldName,
JoinOperator = JoinOperator.Inner,                        
Columns = new ColumnSet(colsAccount),
EntityAlias = AliasName
                        };
query.LinkEntities.Add(linkentity);
This sample shows how to retrieve related entities data using the RetrieveMultiple method using QueryExpression. The code returns columns from the primary entity Account as well as the firstname and lastname from associated Contact record.
Parent Entity:-

 var query = new QueryExpression("account");


 var columnNames = new[] { "fullname", "accountid" };


 query.ColumnSet = new ColumnSet(columnNames);


 query.Criteria.AddCondition("accountid", ConditionOperator.Equal, new Guid(<<ENTER GUID HERE>>));
Linked Entity:-

var colsAccount = new[] { "firstname", "lastname" };


                        LinkEntity linkEntityAccount = new LinkEntity()

                        {


                            LinkFromEntityName = "account",


                            LinkFromAttributeName = "primarycontact",


                            LinkToEntityName = "contact",


                            LinkToAttributeName = "contactid",


                            JoinOperator = JoinOperator.Inner,


                            Columns = new ColumnSet(colsAccount),


                            EntityAlias = "Contacts"


                        };


 query.LinkEntities.Add(linkEntityAccount);     
// Execute Query using RetrieveMultiple
//The RetrieveMultipleRequest is for returning multiple instances of a particular type of entity.
EntityCollection _results = _serviceproxy.RetrieveMultiple(query);
        if (_results != null)
             {
                foreach (var ent in _results.Entities)
               {
     // Display “First Name” along with Alias
     Console.WriteLine((ent.Attributes["Contacts.firstname"] as AliasedValue).Value);
     // Display “Last Name” along with Alias
     Console.WriteLine((ent.Attributes["Contacts.lastname"] as AliasedValue).Value);
                           
}
                        }
 
Hope, this is helpful!

Thanks!