Hi,
Below example will show how to call .Net framework Assembly member from NAV2013R2 using CAL code
1. open Visual Studio and create a class library application
2.Copy and paste below code in class library application
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace UpperCase
{
public class ConverttoUppercase
{
public string customername = "";
public ConverttoUppercase()
{
}
public string ConverttoUp(String Custname)
{
customername = Custname.ToUpper();
return customername;
}
}
}
Below example will show how to call .Net framework Assembly member from NAV2013R2 using CAL code
1. open Visual Studio and create a class library application
2.Copy and paste below code in class library application
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace UpperCase
{
public class ConverttoUppercase
{
public string customername = "";
public ConverttoUppercase()
{
}
public string ConverttoUp(String Custname)
{
customername = Custname.ToUpper();
return customername;
}
}
}
3. Build application (Build -> Build Solution), this will create a dll inside the bin folder of project folder
4. Copy the dll and past it inside "C:\Program Files (x86)\Microsoft Dynamics NAV\71\RoleTailored Client\Add-ins"
5. Create a new code unit
6. Create a global variable with data type as Dotnet and name it as UperCaseAsmbly
7. Click the assist edit button select recently created dll as sub type
8. Go to the properties of Dotnet variable and change RunOnClient property to yes
9. Create one more global variable with data type text and name it as ConvertedString
10. copy and paste below code in OnRun() of code unit
UperCaseAsmbly := UperCaseAsmbly.ConverttoUppercase(); // Constructor Call
ConvertedString := UperCaseAsmbly.ConverttoUp('marshal'); // Method Call
MESSAGE(ConvsertyedString);
11. Save and run code unit.
above example will convert lowercase letters to uppercase and show in message box.
dll which created in step 2 will have a method "ConverttoUp". This method will accept lower case letters and convert it into uppercase and return the result.
When calling .Net framework Assemblies in CAL code first need to call the constructors for public variable, it is not needed for static variables
Thanks
Marshal
Thanks for the post. It's help me alot.
ReplyDeleteDo you think you can post a articel how to loop a DataTable create in DotNet and save the data to a NAV table?
Regards Stefan