Desktop version

Main > Forum > 1C:Enterprise Platform > 1C:Enterprise – Business applications platform > How to programmatically write to catalog

Forum

Search UsersRules
How to programmatically write to catalog
#1
Just came
Points:: 0
Joined:: Oct 9, 2012

Hello,

I need to import a CSV file, split it and write to a pre defined catalogue.

Till now I found now sample how to accrss to fields of a catalogue with write access programmatically - maybe somebody can provide a sample for?

Thank you in advance,
Andre

Profile
#2
Active user
Points:: 0
Joined:: Aug 28, 2015

Hello,
Maybe this can help you:

Here's an example of creating directory and writing a file to it:

DirectoryPath = "C:\Logs";
File = New  File(DirectoryPath);

If Not File.Exist() Then
CreateDirectory(DirectoryPath);
EndIf;

Text = New TextDocument();
Text.AddLine("Hello");
Text.Write("C:\Logs\" +   "Log_" + Format(CurrentDate(),"DF='dd MM yyyy hh mm ss'") + ".txt");

Profile
#3
Just came
Points:: 0
Joined:: Oct 9, 2012

Samir,

thank you but this will not fit.

I like to open file, read from and write to the database - not to a file.

Profile
#4
Active user
Points:: 0
Joined:: Aug 28, 2015

Hello, my apologies for misunderstanding the issue in my previous answer.
Here's new decision that might be useful for you:


Var separator;


Procedure LoadFile(FileName)
ProcessingFile = New TextDocument;
ProcessingFile.Read(FileName);





For StrNo=1 To  ProcessingFile.LineCount() Do


Str = ProcessingFile.GetLine(StrNo);
ColumnsArray = DecomposeStringIntoSubstringsArray(Str,separator);


For ColNo = 1 to ColumnsArray.Count() Do  
       //Getting a value from your file.Then you can use this data for           writing to your predefined catalogue.
CurrentValue = ColumnsArray[ColNo-1];

EndDo;  



EndDo;    


EndProcedure




Function  DecomposeStringIntoSubstringsArray(Str, separator = ",")

StrArray = New  Array();
If separator = " " then
Str = TrimAll(Str);
While  True Do
Pos = Find(Str,separator);
If Pos=0 then
StrArray.Add(Str);
Return StrArray;
EndIf;
StrArray.Add(Left(Str,Pos-1));
Str = TrimL(Mid(Str,Pos));
EndDo;
Else
SeparatorLength = StrLen(separator);
While True Do
Pos = Find(Str,separator);
If Pos=0 then
StrArray.Add(Str);
Return StrArray;
EndIf;
StrArray.Add(Left(Str,Pos-1));
Str = Mid(Str,Pos+SeparatorLength);
EndDo;
EndIf;

EndFunction



separator =";";




Can't write the whole code for filling your catalogue because I don't know its attributes but I'm sure you can do it by yourself. If it's predefined then you must get it as an object, fill the data and save it.
Hope this was helpful good luck!

Profile
#5
Active user
Points:: 0
Joined:: Apr 18, 2012

Hi everyone.

You can use standard function StrSplit instead DecomposeStringIntoSubstringsArray.

Syntax:
StrSplit(<String>, <Separator>, <IncludeBlank>)
Parameters:
<String> (required)
Type: String.
Separated string.
<Separator> (required)

Type: String.
Character string where every character is an individual delimiter.
<IncludeBlank> (optional)

Type: Boolean.
Shows if it is required to include the empty strings which can result from a separation of a source string while calculating the result.
Default value: True.
Returned value:

Type: Array.
Array with strings resulting from splitting of the source string.
Description:

Splits a string into parts according using the specified delimiter.

Availability:

Thin client, web-client, server, thick client, external connection, Mobile application (client), Mobile application (server).

Example
Arr = StrSplit("aaa,bbb,ccc,ddd", ",");

Profile
Subscribe
Users browsing this topic (guests: 1, registered: 0, hidden: 0)



© 1C LLC. All rights reserved
1C Company respects the privacy of our customers and visitors
to our Web-site.