File Upload – FTP

 

Hey Friends,

This post I dedicated in how to upload a file on FTP from NAV. This normally happens when we are doing some sort of processing from a file which has to be processed needs to be downloaded from a FTP and then eventually needs to be processed.

Below is the screenshot of the code that needs to be written.

This one is a very simple example, you can manipulate this as per your need. In the very next post I will come up on dealing with SFTP. This one will work only for FTP.

//RWN
ConnectionString := ‘ftp://your.ftp.address’;

SourceText := ‘Something that you want to write in the file’;

FTPRequest := FTPRequest.Create(ConnectionString);

FTPRequest.KeepAlive := TRUE;
FTPRequest.UseBinary := TRUE;
FTPRequest.Method := ‘STOR’;

FTPRequest.Credentials := NetworkCredential.NetworkCredential(‘UserID’,’Password’);

UTF8Encoding := UTF8Encoding.UTF8Encoding;

FTPRequest.ContentLength := UTF8Encoding.GetBytes(SourceText).Length;
RequestStream := FTPRequest.GetRequestStream;
RequestStream.Write(UTF8Encoding.GetBytes(SourceText),0,FTPRequest.ContentLength);
RequestStream.Close;

FTPResponse := FTPRequest.GetResponse;
MESSAGE(FTPResponse.StatusDescription);
//RWN

Variables

FTPRequest  DotNet System.Net.FtpWebRequest.’System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089′ FTPRequest DotNet System.Net.FtpWebRequest.’System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089′

FTPResponse DotNet System.Net.FtpWebResponse.’System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089′

NetworkCredential DotNet System.Net.NetworkCredential.’System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089′ WebRequestMethods DotNet System.Net.WebRequestMethods.’System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089′

UTF8Encoding DotNet System.Text.UTF8Encoding.’mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089′

RequestStream DotNet System.IO.Stream.’mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089′

ConnectionString Text

SourceText Text

CHEERS

 

 

Advertisements

Extended Text – Item Card

 

Hey Friends,

This page is all about How to Use Extended Text – Extended Text is a base functionality of Dynamics NAV where you can add some custom description for any of the Item which you want to Sell, Purchase etc..

So to use this you simply need to navigate to Item Card and open any of the Item, then and there on the Action Tab you will find a button Extended Text, you need to push this and a new page will open as shown in the below screenshot –

Highlighted part is the area where you need to fill in the text which you want to populate. Below is the Sales, Purchase and Service fast tab where you need to check the Flag where you exactly want this and disable the flags where you don’t.

Now try making a New Sales Order with the same Item for which you did the Setup –

Now as soon as you validate the Item, the Extended Text will automatically get populated as shown in the above screenshot. In the Item card you fill find a Flag Automatic Ext. Text. If this Flag is on then the text will automatically come otherwise you need to manually fill in by navigating to Function -> Insert Ext. Text.

CHEERS

File to Byte Conversion – Client to Server Move

Hey Friends,

This is a very simple post on how to move a file from your client computer to server computer. We all are well equipped and experienced in moving a file directly from a physical path, if we simply need to just copy that file as we all have expertise in using File Management Codeunit.  I just experienced a case where client was scanning the file from NAV and then and there he requested that the scanned file can anyhow directly move into server computer without any physical storage in the current client machine.

As the scanning form was a part of .NET dll so to achieve this and after scanning I sent that scanned file as a parameter in Big-text format to NAV Web Service. Here the actual work comes into play. Look at the below piece of code

//RWN
Byte:=Convert.FromBase64String(FileInBigText); FileInBigText includes scanned file
MemoryStream:=MemoryStream.MemoryStream(Byte);
TempBlob.DELETEALL;
TempBlob.INIT;
TempBlob.Blob.CREATEOUTSTREAM(OutStream);
MemoryStream.WriteTo(OutStream);
TempBlob.INSERT;

File.CREATE(FilePath); Filepath Includes Path + Name + FileType
File.CREATEOUTSTREAM(FileOutStream);
TempBlob.Blob.CREATEINSTREAM(FileInStream);
COPYSTREAM(FileOutStrm,FileInStream);
File.CLOSE;
//RWN

CHEERS

NAV ClickOnce Deployment – Fileshare

 

Hey Friends,

This Post is all about deploying your Dynamics NAV through ClickOnce to your local domain, where each User can access NAV without any dependency of system prerequisites. If you have no idea of ClickOnce then you can have a look on this ClickOnce

So first step what you need to do is to install the ClickOnce from the NAV build. If you have NAV already installed then you just need to open it out and install the ClickOnce setup.

Once you are done with the installation part you need to make a new folder and subfolders in any of your drives and name it like this  FileShare\ClickOnce\Deployment\ApplicationFiles(Name you can choose as per you).

Now you need to navigate to C:\Program Files (x86)\Microsoft Dynamics NAV\71\RoleTailored Client.

rtc

Here from this folder you need to copy all the files from the above mentioned path to – FileShare\ClickOnce\Deployment\ApplicationFiles the one we made above.

After this you need to copy your ConfigSettings from your local app folder(C:\Users\username\AppData\Roaming\Microsoft\Microsoft Dynamics NAV\71)

Now you need to navigate to  – C:\Program Files (x86)\Microsoft Dynamics NAV\71\ClickOnce Installer Tools\TemplateFiles and copy all Files from here to this directory as created above FileShare\ClickOnce\

Now you need to open Command Prompt with admin right and fire the command as shown below – 

  1. Navigate to FileShare\ClickOnce\Deployment\ApplicationFiles from command prompt and fire this command
    1. “C:\Program Files (x86)\Microsoft SDKs\Windows\v8.0A\bin\NETFX 4.0 Tools\mage.exe” -Update Microsoft.Dynamics.Nav.Client.exe.manifest
  2. Navigate to FileShare\ClickOnce\Deployment\ from command prompt and fire this command
    1. “C:\Program Files (x86)\Microsoft SDKs\Windows\v8.0A\bin\NETFX 4.0 Tools\mage.exe” -Update Microsoft.Dynamics.Nav.Client.application -appmanifest ApplicationFiles\Microsoft.Dynamics.Nav.Client.exe.manifest -appcodebase \\fileshare\Clickonce\Deployment\ApplicationFiles\Microsoft.Dynamics.Nav.Client.exe.manifest
  3. You can manually navigate to these two files and cross-verify with current date and time that it’s been successfully updated.
  4. Now you need to open  Microsoft.Dynamics.Nav.Client.application file from Deployment folder as created above and change couple of things like Assembly Identity name as your specific Customer for whom you made this OneClick.

Now you are good to go but again one point is there that you need to take care – You can only access this OneClick from your local computer if you have shared this over network otherwise if you try to access it directly then you will end up with some security zones issue.

So now share your Fileshare folder with all necessary permissions and for those people with whom you truly want to share. Once you are done with this, Please try to access this in your windows explorer

\\ComputerIP\FileShare\ClickOnce\Deployment\

Now try to open your Microsoft.Dynamics.Nav.Client application manifest, a dialogue box will come which will ask you to install it up, if it ends up with an error then you need to open the log and check the error log.

Install the application and enter the valid ID and Password and you will be logged in to NAV RTC Environment.

CHEERS..

Check Valid Zip Code

 

Hey Friends,

This Post is all about validating a proper Zip Code. Just 2 3 lines of code needed and you can validate your zip code. So below is the line of code that you just need to write.

 

 

 

 

 

 

 

//RWN
IF NOT Regex.Match(ZipCode, ‘^\d{5}$’ ).Success THEN
EXIT(FALSE)
ELSE
EXIT(TRUE);
//RWN

Regex           DotNet                  System.Text.RegularExpressions.Regex.’System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089′

CHEERS

Custom Form – Dynamics NAV

Hey Friends,

As we all know we have certain limitations while designing a Page in NAV, i.e. We deliberately cant design our NAV Page as we want to, Actions OR Buttons must be on the Top, We cant make buttons somewhere on the middle of the Page, We can’t design a page in which we can have multiple controls like Buttons, Radio Buttons and so on and possibly anywhere on the Page.

This limitation could be sorted out if we have certain hands on, on Dot Net variables. I just got a requirement where client was asking for certain design on the Page as per his requirement and he hardly cares for the limitations. So I just make a custom Windows Form which anyhow fulfilled his requirement.

You have the liberty to add n number of buttons or other controls or how badly you want to customise it.

//RWN
WinForm := WinForm.Form;
Colour := Colour.Color;
WinText := WinText.TextBox;
WinForm.MaximizeBox(FALSE);
WinForm.Width := 733;
WinForm.Height := 415;
WinForm.ActiveForm;
WinForm.BackColor := Colour.Green;
WinForm.ForeColor := Colour.Green;
WinForm.BackgroundImageLayout(Layout.Center);
WinForm.FormBorderStyle(FormBorderStyle.SizableToolWindow);
WinForm.Text := ‘SMS BODY’;
WinForm.StartPosition := StartPosition.Manual;
WinText.BackColor(Colour.LightBlue);
WinText.Font(Font.Font(‘Algerian’,12));
WinText.Width(733);
WinText.Height(415);
WinText.Multiline(TRUE);
WinForm.Controls.Add(WinText);
WinForm.ShowDialog;
//RWN

 
WinForm         DotNet       System.Windows.Forms.Form.’System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089′

 
WinText          DotNet        System.Windows.Forms.TextBox.’System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089′

 
Colour            DotNet          System.Drawing.Color.’System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a’

Off The Topic – Shutdown Machine from NAV

Hey Friends,

This Post is just a part of Brainstorming, and doing a research worth needed having out of the box thought that If Client just want to shutdown Machine directly from NAV. Though it will never be demanded but on the counterpart Client Expectation has no limits. 🙂

The interesting part is it’s just a single line of Code which will do the Job .

//RWN
Process.Start(‘shutdown’,’/s /t 0′); – Shutdown
Process.Start(‘shutdown’,’/r /t 0′); – Restart
//RWN

Process – DotNet – System.Diagnostics.Process.’System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089′

CHEERS

 

Make NAV User – SQL + PowerShell

Hey Friends,

It’s a very simple Post on how to make a NAV User from SQL/Powershell. Many times we end up with the following Error.

0

Though if you are first user login in then you can follow this POST to quickly solve it out, but if there are many valid users then obviously not.

So the first step that need to be done is to open Powershell ISE with Administrator privilege. Now execute this command

capture

//RWN
$objUser = New-Object System.Security.Principal.NTAccount(“DOMAIN\USER”)
$strSID = $objUser.Translate([System.Security.Principal.SecurityIdentifier])
$strSID.Value
//RWN

Once you will execute the above command, you will get the SID number. Save it off in Notepad OR somewhere. It will be used in the second step.

Now open SQL Server and you need to execute the following Query for that Database in which you wants your respective login. Paste the SID and the Username copied above. 

capture

–RWN
DECLARE @USERSID uniqueidentifier, @WINDOWSSID nvarchar(119), @USERNAME nvarchar(50), @USERSIDTXT varchar(50)

SET @USERNAME = ‘DOMAIN\USER
SET @USERSID = NEWID()
SET @USERSIDTXT = CONVERT(VARCHAR(50), @USERSID)
SET @WINDOWSSID = ‘YOUR COPIED SID

INSERT INTO [dbo].[User]
([User Security ID],[User Name],[Full Name],[State],[Expiry Date],[Windows Security ID],[Change Password],[License Type]
,[Authentication Email])
VALUES
(@USERSID,@USERNAME,”,0,’1753-01-01 00:00:00.000′,@WINDOWSSID,0,0,”)

INSERT INTO [dbo].[User Property]
([User Security ID],[Password],[Name Identifier],[Authentication Key],[WebServices Key],[WebServices Key Expiry Date],
[Authentication Object ID])
VALUES
(@USERSID,”,”,”,”,’1753-01-01 00:00:00.000′,”)

INSERT INTO [dbo].[Access Control]
([User Security ID],[Role ID],[Company Name])
VALUES
(@USERSID,’SUPER’,”)
GO
–RWN

Execute the above command. If it gets successfully executed then you can go and try to login and you will get logged in to RTC.

Basic Date Calculations

 

Hey Friends,

This Post is all about DATE. I saw many people getting stuck as whenever there needs some date calculation logic and the only reason behind this is that there are too many permutation and combinations that comes into play whenever we start creating our logic. So I just though to add a post where I can add all those very commonly needed outcomes.

FirstDayOfMonth := CALCDATE (‘<CM-1M+1D>’, Today);

LastDayOfMonth := CALCDATE (‘<CM>’, Today);

FirstDayOfPreviousMonth := CALCDATE (‘<CM-2M+1D>’, Today);

LastDayOfPreviousMonth := CALCDATE(‘CM’,CALCDATE(‘-CM-1D’,TODAY));

Day := DATE2DMY(TODAY, 1);

Month := DATE2DMY(TODAY, 2);

Year := DATE2DMY(TODAY, 3);

WD4 The next 4th day of a week (Thursday)
CM+10D Current Month +10D
10D 10 Days from today
CW Last date of the current week (Sunday)
CM Last day of the current month
CQ Last day of the current quarter
CY Last day of the current year
1Y    1 Year ago from today
CY-2Y+1D First Day of last fiscal year
CY-1Y Last Day of last fiscal year
2W 2 weeks from today
D10 The next 10th day of the month

I will go on increasing this list. This will anyhow save our time.

There’s a virtual Table called DATE. I always remind and recommend everyone to use this Table, it really makes the work a more easier. 

CHEERS

Remove Attribute – Soap Request XML(XmlPort)

 

Hey Friends,

We all know how to remove Namespaces from the XML if we want to import it from NAV XmlPort, I just faced a situation where I was using XmlPort to send Soap Request with Default Namespace. Using default namespace creates an attribute something like this (xmlns:xx=”http://xx.org/soap/envelope/&#8221;) in the soap::Body which basically disrespects the Soap request as sometimes it’s not needed in the protocol of the soap request. So now if we use Remove Namespace code then it will remove the namespaces from the entire XML i.e. Soap:Header as well. In this case here is the code that you need to write to just eliminate it from the soap:Body.

untitled

Now when you load this BigTextOutputValue to your XmlDoc, you will have a XML with no Attributes in the Soap:Body and you can send this as a Soap Request via HTTP.

BigTextVaue  –   DateType  – BigText

BigTextOutputVaue  –   DateType  – BigText

CHEERS.