How to programmatically write to catalog


If you wish to leave comments or ask questions, please log on or sign up.

The 1C:Enterprise developers forum

#1
People who like this:0Yes/0No
Just came
Rating: 1
Joined: Oct 9, 2012
Company: Net Lap Consulting GmbH

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

 
#2
People who like this:0Yes/0No
Active user
Rating: 2
Joined: Aug 28, 2015
Company:

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");

Edited: Samir Muqimov - Jan 05, 2018 07:28 AM
 
#3
People who like this:0Yes/0No
Just came
Rating: 1
Joined: Oct 9, 2012
Company: Net Lap Consulting GmbH

Samir,

thank you but this will not fit.

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

 
#4
People who like this:0Yes/0No
Active user
Rating: 2
Joined: Aug 28, 2015
Company:

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!

Edited: Samir Muqimov - Jan 14, 2018 09:28 AM
 
#5
People who like this:0Yes/0No
Active user
Rating: 5
Joined: Apr 18, 2012
Company:

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", ",");

 
Subscribe