handling-bc-files
Skill1 starsChanged 10 months agoMITView on GitHub
Uploads and downloads files using InStream/OutStream, attaches documents to records via Table 1173, imports and exports CSV/XML with XMLport, and stores blobs in Azure Storage. Use when adding file attachments to sales orders, importing data from CSV, exporting reports to files, or connecting to Azure Blob Storage.
In this repository12 other files it gives its agents.
- AGENTS.mdAGENTS.md
- authenticating-with-oauthSkill
- binding-event-subscribersSkill
- building-cue-rolecentersSkill
- consuming-bc-standard-apiSkill
- controlling-al-accessSkill
- creating-bc-custom-apiSkill
- implementing-al-interfacesSkill
- implementing-telemetrySkill
- integrating-azure-servicesSkill
- optimizing-bc-performanceSkill
- writing-git-commitsSkill
The file
We split this skill into the rules it gives an agent
2 rules. About 0 are common, 1 is distinctive, and 1 is very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 17
Note: ALWAYS CalcFields(BlobField) before CreateInStream.
- Distinctive: line 124
⚠️ NOT for permanent storage - causes locking issues.
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Skill: AL File Handling
Validation Gates
- After Step 1:
UploadIntoStreamopens file dialog, InStream contains data - After Step 2: Attachment saved to Document Attachment or custom table
- Final: XMLport imports/exports successfully, Azure Blob upload returns
IsSuccessful()
Note: ALWAYS CalcFields(BlobField) before CreateInStream. Web Client allows only ONE DownloadFromStream per request.
Procedure
Step 1: Upload/Download Files
// Upload
if UploadIntoStream('Select file', '', 'All Files (*.*)|*.*', FileName, InStr) then
// Process InStr
// Download - MUST CalcFields first for Blob
CalcFields("File Content");
if "File Content".HasValue() then begin
"File Content".CreateInStream(InStr);
DownloadFromStream(InStr, '', '', '', FileName);
end;Step 2: Document Attachments
Standard (Table 1173):
// Replace <SourceTable> and field names with your record
DocumentAttachment.Init();
DocumentAttachment.Validate("Table ID", Database::<SourceTable>);
DocumentAttachment.Validate("No.", <Record>."<KeyField>");
DocumentAttachment.Validate("Document Type", <Record>."<TypeField>"); // If applicable
DocumentAttachment.InsertFromStream(InStr, FileName);Custom Blob field:
Rec."File Content".CreateOutStream(OutStr);
CopyStream(OutStr, InStr);
Rec.Modify();Step 3: XMLport Import/Export
xmlport <ID> "<PREFIX> Import Data"
{
Direction = Import;
Format = VariableText;
FieldDelimiter = '"';
FieldSeparator = ';';
TextEncoding = UTF8;
schema
{
textelement(Root)
{
tableelement(TempImport; "<PREFIX> Import Buffer")
{
UseTemporary = true;
AutoSave = false;
fieldelement(ItemNo; TempImport."Item No.") { }
fieldelement(Description; TempImport.Description) { }
trigger OnAfterInsertRecord()
begin
ProcessLine(TempImport);
end;
}
}
}
}Key properties: Direction (Import/Export/Both), Format (Xml/VariableText/FixedText), TextEncoding (UTF8/UTF16)
Step 4: Azure Blob Storage (Optional)
var
ABSBlobClient: Codeunit "ABS Blob Client";
StorageServiceAuthorization: Codeunit "Storage Service Authorization";
Authorization: Interface "Storage Service Authorization";
begin
Authorization := StorageServiceAuthorization.CreateSAS(GetSASToken());
ABSBlobClient.Initialize(AccountName, ContainerName, Authorization);
// Upload
TempBlob.CreateInStream(InStr);
ABSOperationResponse := ABSBlobClient.PutBlobBlockBlobStream(BlobName, InStr);
// Download
ABSOperationResponse := ABSBlobClient.GetBlobAsStream(BlobName, InStr);
end;Requires: Azure Storage Account + SAS Token in Isolated Storage.
Persistent Blob (Cross-Session)
// Store (returns GUID key)
BlobKey := PersistentBlob.Create();
PersistentBlob.CreateOutStream(OutStr);
OutStr.WriteText(Data);
// Retrieve
PersistentBlob.CreateInStream(BlobKey, InStr);
InStr.ReadText(Data);
PersistentBlob.Delete(BlobKey); // Clean up⚠️ NOT for permanent storage - causes locking issues.
JSON/XML Quick Reference
// JSON
JsonObj.Add('key', 'value');
JsonObj.WriteTo(JsonText);
JsonObj.ReadFrom(JsonText);
if JsonObj.Get('key', JsonTok) then MyText := JsonTok.AsValue().AsText();
// XML
XmlDoc := XmlDocument.Create();
XmlDoc.Add(XmlElement.Create('Root'));
XmlDocument.ReadFrom(XmlText, XmlDoc);
XmlDoc.SelectSingleNode('//Child', XmlNode);External Documentation
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

