Records, RecordIDs, and RecordRefs OH MY!

bhalpin
Member Posts: 309
Arg.
Ok, I grew up on MS C/Side documentation examples like:
Sally works in finance, and likes cats. Not all cats, just fluffy ones. Sally wants to know how often a customer has ordered a particular item. So she asks Todd in I.T., but he' been unable to overcome his breakup with Sally and is off sick from severe allergy reactions to her cat(s). So she turns to Todd's boss Anne. She escalates her request to management with a proposal that includes new servers, a company car, and a corner office. When in that office she turns to Mibuso and within five minutes has his answer. Copy - Paste - and Viola!
:-)
Ok (again) - I'm Todd - sort-of. (I'm not allergic to cats - just crummy documentation.) All I need is a nudge here. (And maybe win Sally back)
I've read about and played with RecordRefs, etc, and have a headache. This is all I want to do:
Function1
Customer.GET('C1');
or
Item.GET(I1);
// Whatever
Now I want to call Function2 with some sort of variable that Function2 can determine what table number / record type (Customer or Item) the caller is sending, and what the key field(s) are for that record.
Function 2
// Takes a parameter that - like specified above - allows me to determine what table number (Customer or Item) I'm called with, and the primary key(s) of that record. I then want to retrieve that record using a 'normal' record variable using a CASE statement like
CASE TableNo OF
## - Get a ## record using primary key value(s)
### - Get a ### record using primary key value(s)
I can't promise a company car for help here - only my sincere thank!
Bob
Ok, I grew up on MS C/Side documentation examples like:
Sally works in finance, and likes cats. Not all cats, just fluffy ones. Sally wants to know how often a customer has ordered a particular item. So she asks Todd in I.T., but he' been unable to overcome his breakup with Sally and is off sick from severe allergy reactions to her cat(s). So she turns to Todd's boss Anne. She escalates her request to management with a proposal that includes new servers, a company car, and a corner office. When in that office she turns to Mibuso and within five minutes has his answer. Copy - Paste - and Viola!
:-)
Ok (again) - I'm Todd - sort-of. (I'm not allergic to cats - just crummy documentation.) All I need is a nudge here. (And maybe win Sally back)
I've read about and played with RecordRefs, etc, and have a headache. This is all I want to do:
Function1
Customer.GET('C1');
or
Item.GET(I1);
// Whatever
Now I want to call Function2 with some sort of variable that Function2 can determine what table number / record type (Customer or Item) the caller is sending, and what the key field(s) are for that record.
Function 2
// Takes a parameter that - like specified above - allows me to determine what table number (Customer or Item) I'm called with, and the primary key(s) of that record. I then want to retrieve that record using a 'normal' record variable using a CASE statement like
CASE TableNo OF
## - Get a ## record using primary key value(s)
### - Get a ### record using primary key value(s)
I can't promise a company car for help here - only my sincere thank!
Bob
1
Comments
-
Hello bhalpin,
if you pass the recordid you can work with recref and settable.
Example:
You are at the Item Card and press a button. Inside OnAction() you pass the recordid.
TestButton - OnAction()GetMyRecord(Rec.RECORDID);
GetMyRecord(recid : RecordID)LOCAL GetMyRecord(recid : RecordID) IF recref.GET(recid) THEN BEGIN recref.SETTABLE(recItem); MESSAGE(recItem."No."); END;
Parameter:Var Name DataType Subtype Length No recid RecordID
Variables:Name DataType Subtype Length recref RecordRef recItem Record Item
In your case you can simple expand it with the case function. You just have to use recid.TABLENO.0 -
Just what I wanted. Thanks!
But, no joy. I tried a simple example (NAV 2015) and get this error:
0 -
Oh - that's unfortunate. Sorry.
I guess it was just added later.
Anyway,
in that version you should be able to use the recref as parameter.
Example:
TestButton - OnAction()recref.GETTABLE(Rec); GetMyRecord(recref);
Variable:Name DataType Subtype Length recref RecordRef
GetMyRecord(recid : RecordID)LOCAL GetMyRecord(recref : RecordRef) recref.SETTABLE(recItem); MESSAGE(recItem."No.");
Parameter:Var Name DataType Subtype Length No recref RecordRef
Variable:Name DataType Subtype Length recItem Record Item
With recref.NUMBER you can get the Table ID.
0 -
Hi,
You can create a function with Variant variable as parameter and pass any record/recordref/recordid to it.
Inside the function you can convert variant to RecordRef;GetRecordRef(Variant: Variant) CASE TRUE OF Variant.ISRECORD: RecRef.GETTABLE(Variant); Variant.ISRECORDREF: RecRef := Variant; Variant.ISRECORDID: RecRef.GET(Variant); ELSE ERROR('Invalid parameter'); END; Message('%1', RecRef.RECORDID);
0 -
Thanks to both! I have a solution now.
I'm still curious why Record.RECORDID doesn't compile though.
Life is too short to dwell on it though.
Thanks again!0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions