How to insert record Id in record link table using SQL in Dynamics Nav

Khushboo1626
Member Posts: 7
in SQL General
How to insert record Id in record link table using SQL in Dynamics Nav,
thanks in advance.
thanks in advance.
0
Best Answer
-
Hi,
Try to use function WriteRecordLinkNote() from Codeunit 10 "Type Helper" to save notes.5
Answers
-
Never do that. Try to find scenario to create links by NAV.0
-
It is not possible. You need to do that through NAV code.
Regards,Alain Krikilion
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!0 -
Actually it's possible, at least in NAV 2009, where I get somewhere the RecordID format
This is the code in Powershell to create the RecordID#--------------------------------------------------------------------------------------------------------- function createRecordID { #--------------------------------------------------------------------------------------------------------- Param ( [Parameter(Mandatory=$True)] [string]$documento ) $long = 7 + $documento.Length + 3 $sqlBytes = new-object System.Data.SqlTypes.SqlBytes # -ArgumentList $long $sqlBytes = new-object byte[] -ArgumentList $long $sqlBytes[0] = 110 # Table number $sqlBytes[1] = 0 $sqlBytes[2] = 0 $sqlBytes[3] = 0 $sqlBytes[4] = 0 $sqlBytes[5] = 137 # code field $sqlBytes[6] = 255 # alfanuméric for($i=0; $i -lt $documento.Length; $i++){ $sqlBytes[$i+7] = [byte][char]$documento.Substring($i, 1) } $sqlBytes }
And you can do the insert with this code#--------------------------------------------------------------------------------------------------------- function insRecordID { #--------------------------------------------------------------------------------------------------------- Param ( [Parameter(Mandatory=$True)] [string]$FileName, [Parameter(Mandatory=$True)] [string]$documento ) $query = @" SELECT [Record ID],[URL1] FROM [dbo].[Record Link] WHERE ([Record ID] = @RecordID) AND ([URL1] = @URL1) "@ $connection=new-object System.Data.SqlClient.SQLConnection $connection.ConnectionString="Server={0};Database={1};User={2};Password={3}" -f $server,$database,$user,$pass $command=new-object system.Data.SqlClient.SqlCommand($query,$connection) $command.CommandTimeout=120 $connection.Open() [byte[]]$bytes = ceateRecordID($documento) $command.Parameters.Add("@RecordID", [System.Data.SqlDbType]"VarBinary", $sqlBytes.Length) | Out-Null $command.Parameters["@RecordID"].Value = $bytes $command.Parameters.Add("@URL1", [System.Data.SqlDbType]"NChar") | Out-Null $command.Parameters["@URL1"].Value = $FileName $resultado = $command.ExecuteReader() if (!$resultado.Read()) { $query = @" INSERT [Record Link] ([Record ID] ,[URL1] ,[URL2] ,[URL3] ,[URL4] ,[Description] ,[Type] ,[Note] ,[Created] ,[User ID] ,[Company]) VALUES (@RecordID, @URL1, '', '', '', @Desc, 0, '', @Created, @UserID, @Company) "@ $command=new-object system.Data.SqlClient.SqlCommand($query,$connection) $command.CommandTimeout=120 $command.Parameters.Add("@RecordID", [System.Data.SqlDbType]"VarBinary", $sqlBytes.Length) | Out-Null $command.Parameters["@RecordID"].Value = $bytes $command.Parameters.Add("@URL1", [System.Data.SqlDbType]"NChar") | Out-Null $command.Parameters["@URL1"].Value = $FileName [string]$Desc = Split-Path $FileName -Leaf $command.Parameters.Add("@Desc", [System.Data.SqlDbType]"NChar") | Out-Null $command.Parameters["@Desc"].Value = $Desc $command.Parameters.Add("@Company", [System.Data.SqlDbType]"NChar") | Out-Null $command.Parameters["@Company"].Value = $empresaNAV $command.Parameters.Add("@UserID", [System.Data.SqlDbType]"NChar") | Out-Null $command.Parameters["@UserID"].Value = $user $command.Parameters.Add("@Created", [System.Data.SqlDbType]"DateTIme") | Out-Null $Fecha = (Get-Date).ToUniversalTime().ToString("yyyy-MM-dd HH:mm:ss.fff") $command.Parameters["@Created"].Value = $Fecha $command.ExecuteNonQuery() $connection.Close() } else { $connection.Close() LogError(' >> Registro ya existe >>>>> ' + $documento) return 1 } }
0 -
The problem with me is when i try to import data using xmlport in record link table the view shows missing data while i insert same data manually it shows complete data but the data in table in inserted fully when i import using xmlport,
refer the screenshots :
0 -
1. Create RecordRef variable
2. Find requested record
3. Use Recordref.RecordID
It is simply and clear ... and probably much more faster
0 -
@lubost i have used recordref only0
-
-
Hi,
Try to use function WriteRecordLinkNote() from Codeunit 10 "Type Helper" to save notes.5 -
@AlexDen Thanks it worked perfectly0
-
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions