Get should be used before Modify after RecordId.GetRecord #1218
JohnnyUndercover
started this conversation in
New Rule
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
The GetRecord procedure on the RecordId does not really get the record, it just sets the primary key fields on a empty record.
So if you do
MyRecord.Init();
MyRecord.PkField := 'CODE1';
MyRecord.Field2 := 'Some important value';
MyRecord.Insert();
...
MyRecord := Code1RecordId.GetRecord();
MyRecord.Field3 := 'Some value';
MyRecord.Modify();
The result will be this:
MyRecord.PkField => 'CODE1';
MyRecord.Field2 => '';
MyRecord.Field3 => 'Some value';
The behavior of the GetRecord method is documented but at least to me it was not obvious that i do need to do a get after the GetRecord, to actually Get the whole record.
https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/methods-auto/recordid/recordid-getrecord-method
Would be nice to have a rule that gives a warning in this case.
All reactions