Skip to content

Commit

Permalink
Ability to replace only part of field or entire field value
Browse files Browse the repository at this point in the history
  • Loading branch information
Drakonian committed Feb 22, 2025
1 parent 4e661fe commit db3230c
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 4 deletions.
43 changes: 40 additions & 3 deletions Source/Pages/Pag81007.DETFindandReplace.al
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand All @@ -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;
Expand Down Expand Up @@ -300,5 +336,6 @@ page 81007 "DET Find and Replace"
GlobalWithoutValidate: Boolean;
MatchCase: Boolean;
MatchEntireFieldValue: Boolean;
ReplaceEntireValue: Boolean;
GlobalGuid: Guid;
}
10 changes: 10 additions & 0 deletions Source/Translations/Data Editor Tool.g.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -4753,6 +4753,16 @@
<note from="Developer" annotates="general" priority="2"></note>
<note from="Xliff Generator" annotates="general" priority="3">Page DET Find and Replace - Control MatchEntireFieldValue - Property Caption</note>
</trans-unit>
<trans-unit id="Page 77930169 - Control 1489689570 - Property 1295455071" size-unit="char" translate="yes" xml:space="preserve">
<source>Replace Entire Field Value</source>
<note from="Developer" annotates="general" priority="2"></note>
<note from="Xliff Generator" annotates="general" priority="3">Page DET Find and Replace - Control ReplaceEntireValue - Property ToolTip</note>
</trans-unit>
<trans-unit id="Page 77930169 - Control 1489689570 - Property 2879900210" size-unit="char" translate="yes" xml:space="preserve">
<source>Replace Entire Field Value</source>
<note from="Developer" annotates="general" priority="2"></note>
<note from="Xliff Generator" annotates="general" priority="3">Page DET Find and Replace - Control ReplaceEntireValue - Property Caption</note>
</trans-unit>
<trans-unit id="Page 77930169 - Control 3537699386 - Property 1295455071" size-unit="char" translate="yes" xml:space="preserve">
<source>Replace With</source>
<note from="Developer" annotates="general" priority="2"></note>
Expand Down
2 changes: 1 addition & 1 deletion Source/app.json
Original file line number Diff line number Diff line change
Expand Up @@ -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/",
Expand Down

0 comments on commit db3230c

Please sign in to comment.