From db3230c0460870701e753c996d1dbb6eeb3839d6 Mon Sep 17 00:00:00 2001 From: Volodymyr Dvernytskyi Date: Sat, 22 Feb 2025 12:47:42 +0200 Subject: [PATCH] Ability to replace only part of field or entire field value --- Source/Pages/Pag81007.DETFindandReplace.al | 43 ++++++++++++++++++++-- Source/Translations/Data Editor Tool.g.xlf | 10 +++++ Source/app.json | 2 +- 3 files changed, 51 insertions(+), 4 deletions(-) diff --git a/Source/Pages/Pag81007.DETFindandReplace.al b/Source/Pages/Pag81007.DETFindandReplace.al index 2b4e5ba..575165e 100644 --- a/Source/Pages/Pag81007.DETFindandReplace.al +++ b/Source/Pages/Pag81007.DETFindandReplace.al @@ -33,6 +33,11 @@ page 81007 "DET Find and Replace" ToolTip = 'Replace With'; Caption = 'Replace With'; } + field(ReplaceEntireValue; ReplaceEntireValue) + { + ToolTip = 'Replace Entire Field Value'; + Caption = 'Replace Entire Field Value'; + } field(MatchCase; MatchCase) { ToolTip = 'Match Case'; @@ -131,6 +136,7 @@ page 81007 "DET Find and Replace" FieldRefVar: FieldRef; EntryNo: Integer; FieldCounter: Integer; + FieldValueAsTxt: Text; FindWhatFilter: Text; FoundFieldList: List of [Integer]; ReplacedCounter: Integer; @@ -200,11 +206,19 @@ page 81007 "DET Find and Replace" if Replace and Rec."Is Editable" then begin FieldRefToModify := RecRef.Field(Rec."Field Number"); xFieldRefToModify := xRecRef.Field(Rec."Field Number"); + + FieldValueAsTxt := Format(FieldRefToModify.Value()); + if ReplaceEntireValue then + FieldValueAsTxt := ReplaceWith + else + ReplaceNoCase(FieldValueAsTxt, FindWhat, ReplaceWith); + if GlobalWithoutValidate then - FieldRefToModify.Value(ReplaceWith) + FieldRefToModify.Value(FieldValueAsTxt) else - FieldRefToModify.Validate(ReplaceWith); - Rec."Field Value" := CopyStr(ReplaceWith, 1, MaxStrLen(Rec."Field Value")); + FieldRefToModify.Validate(FieldValueAsTxt); + + Rec."Field Value" := CopyStr(FieldValueAsTxt, 1, MaxStrLen(Rec."Field Value")); ReplacedCounter += 1; if IsLogEnabled then DataEditorMgt.LogModify(RecRef.Number(), FieldRefToModify.Number(), RecRef.RecordId(), xFieldRefToModify, @@ -228,6 +242,28 @@ page 81007 "DET Find and Replace" ResultNotification.Send(); end; + procedure ReplaceNoCase(var TextVariable: Text; OldValue: Text; NewValue: Text) + var + Position: Integer; + OldValueLen: Integer; + begin + if OldValue = '' then + exit; + + OldValueLen := StrLen(OldValue); + + repeat + Position := StrPos(LowerCase(TextVariable), LowerCase(OldValue)); + + if Position > 0 then + TextVariable := + CopyStr(TextVariable, 1, Position - 1) + + NewValue + + CopyStr(TextVariable, Position + OldValueLen); + until Position = 0; + end; + + local procedure SetCustomFilter() var CustomFilterPageBuilder: FilterPageBuilder; @@ -300,5 +336,6 @@ page 81007 "DET Find and Replace" GlobalWithoutValidate: Boolean; MatchCase: Boolean; MatchEntireFieldValue: Boolean; + ReplaceEntireValue: Boolean; GlobalGuid: Guid; } diff --git a/Source/Translations/Data Editor Tool.g.xlf b/Source/Translations/Data Editor Tool.g.xlf index 1d77c54..edaab12 100644 --- a/Source/Translations/Data Editor Tool.g.xlf +++ b/Source/Translations/Data Editor Tool.g.xlf @@ -4753,6 +4753,16 @@ Page DET Find and Replace - Control MatchEntireFieldValue - Property Caption + + Replace Entire Field Value + + Page DET Find and Replace - Control ReplaceEntireValue - Property ToolTip + + + Replace Entire Field Value + + Page DET Find and Replace - Control ReplaceEntireValue - Property Caption + Replace With diff --git a/Source/app.json b/Source/app.json index 1ccd45c..737854c 100644 --- a/Source/app.json +++ b/Source/app.json @@ -2,7 +2,7 @@ "id": "e28d62da-ceb0-46e7-9e06-774bc46f4bac", "name": "Data Editor Tool", "publisher": "Volodymyr Dvernytskyi", - "version": "4.0.0.1", + "version": "4.0.0.2", "brief": "https://vld-bc.com/", "description": "https://vld-bc.com/", "privacyStatement": "https://vld-bc.com/",