mibuso.com

Microsoft Business Solutions online community
It is currently Thu May 23, 2013 7:29 am

All times are UTC + 1 hour [ DST ]




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: RecRef and Form.runmodal(ID,record)
PostPosted: Tue Jan 03, 2006 9:57 pm 
Offline

Joined: Mon Mar 08, 2004 2:42 pm
Posts: 3255
Location: Hannover
Country: Germany (de)
If you select, modify or insert many Record in different tables per RecRef and you will see the result in the "original" form (like 21 for Customer), you can use this codeexample to run the original Form without creating a Record variable (like 18 for customer). But you must know the formid that you will run.

Code: Select all
.
.
.
RecRef.OPEN(18); //this you know
.
.
.

//Here we will open the base form to an Record

HYPERLINK(CreateHyperlink(RecRef,21);
RecRef.CLOSE();


CreateHyperlink(VAR RecRef : RecordRef;FormID : Integer) : Text[1024]

PreFix := '0'; //Form, Report ist 1

KeyString := FORMAT(RecRef.KEYINDEX(1));  //PK

FieldNoTxt := DELCHR(KeyString,'=','Field');

REPEAT
  IF (STRPOS(FieldNoTxt,',') > 1) THEN BEGIN
    SingleNoTxt := COPYSTR(FieldNoTxt,1,STRPOS(FieldNoTxt,',') - 1);
    EVALUATE(FieldNo,SingleNoTxt);
    FieldValue := FORMAT(RecRef.FIELD(FieldNo).VALUE);
    FieldNoTxt := COPYSTR(FieldNoTxt,STRPOS(FieldNoTxt,',') + 1,100);
    PosStr := PosStr + 'Field' + SingleNoTxt + '=' +
                      PreFix + '(%22' + FieldValue + '%22),';
  END;
UNTIL (STRPOS(FieldNoTxt,',') = 0);

EVALUATE(FieldNo,FieldNoTxt);
FieldValue := FORMAT(RecRef.FIELD(FieldNo).VALUE);
PosStr := PosStr + 'Field' + FORMAT(FieldNo) +
                  '=' + PreFix + '(%22' + FieldValue + '%22)';

TxtStr := CONTEXTURL + '%26target=Form' + '%20' +
              FORMAT(FormID) + '%26view=SORTING(' + FORMAT(KeyString) + ')' +
              '%26position=' + PosStr;

EXIT(TxtStr);


Regards Garak

PS: Can the admin delete the second post. Thanks

_________________
Do you make it right, it works too!


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 20, 2006 5:00 pm 
Offline

Joined: Mon May 09, 2005 9:35 am
Posts: 46
Location: Vilnius
Country: Lithuania (lt)
There is another solution for that problem. The general idea is based that you create your own codeunit with function "Lookup", which runs a specified record form. For ex.:

Code: Select all
Lookup(p_txtFieldName : Text[250];VAR p_txtResult : Text[1024]) booResult : Boolean
...
rrfMain: RecordRef;
recTmp: Record 15;
frfMain: FieldRef;
...

booResult := FALSE;
p_txtResult := '';
IF FORM.RUNMODAL(0, recTmp) = ACTION::LookupOK THEN
BEGIN
  rrfMain.GETTABLE(recTmp);
  .. assign frfMain by p_txtFieldName ..
  p_txtResult := FORMAT(frfMain.VALUE);
  booResult := TRUE;
END;


and then, whenever you want to lookup another table, you have to export the blob of codeunit above to file/stream (it is stored in table Object), change the binary code of exported file/stream so that new ID of recTmp would be assigned and import the blob back to table Object.

You can find the places where navision stores the record No by exporting blob of codeunit with several variations of record No of recTmp in codeunit above. In my situation it changes in two places: from bytes 536 and 1088.

The code would look like smth like that:
Code: Select all
...
recObject: Record 'Object';
fleMain: File;
i: Integer;
...
recObject.GET(recObject.Type::Codeunit, '', 50010);
recObject.CALCFIELDS("BLOB Reference");
recObject."BLOB Reference".EXPORT(<tmp file>);
i := <table id you want to lookup>;

fleMain.WRITEMODE:= TRUE;
fleMain.TEXTMODE := FALSE;
fleMain.OPEN(<tmp file>);
fleMain.SEEK(536); // 536 must be changes in your situation
fleMain.WRITE(i);

fleMain.SEEK(1088); // 1088 must be changed in your situation
fleMain.WRITE(i);
fleMain.CLOSE;

recObject."BLOB Reference".IMPORT(<tmp file>);
recObject.MODIFY(TRUE);
COMMIT;
booResult := <your codeunit>.Lookup(<field name>, p_txtResult);


This smells of 'breaking navision', but it works great! Even with several concurent users. But just be carefull with user permissions for table 'Object'.

Have fun!

_________________
http://www.brain-tune.com/
http://navisionfreak.blogspot.com/
Justas Janauskas


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 15, 2008 11:08 pm 
Offline

Joined: Thu Jul 17, 2003 10:52 pm
Posts: 638
Location: Capelle a/d IJssel
Country: Netherlands (nl)
@jjanauskas
Thx, it does work in 4.0 and later on in 5.0. even with the same fob.

_________________
Create dynamic Excel or Word documents, ReportX


Top
 Profile  
 
 Post subject: Re: RecRef and Form.runmodal(ID,record)
PostPosted: Sat Dec 17, 2011 11:48 am 
Offline

Joined: Sat Dec 17, 2011 11:46 am
Posts: 3
Country: Slovenia (si)
Not sure about the older versions, but in NAV 2009 R2 this can be done with the use of Variant datatype:

Code: Select all
rRef: RecordRef;
var: Variant;

rRef.OPEN(18); //Customer
var := rRef;
FORM.RUNMODAL(0,var);



The only problem is that you can not apply filters to the record, because they get lost when you assign RecRef to the Variant variable. First record in the filter DOES get selected though. Example below:


Code: Select all
rRef.OPEN(18); //Customer
rRef.FILTERGROUP(5);
fRef := rRef.FIELD(2); //Customer.Name
fRef.SETFILTER('T*');
rRef.FILTERGROUP(0);
rRef.FINDSET;
var := rRef;
FORM.RUNMODAL(0,var); //Form shows all records but is focused on the first that fits in the filter 'T*'.



I hope that helps someone else too.


Top
 Profile E-mail  
 
 Post subject: Re: RecRef and Form.runmodal(ID,record)
PostPosted: Tue May 21, 2013 12:25 am 
Offline

Joined: Thu Feb 08, 2007 4:01 am
Posts: 27
Location: San Diego, CA
Country: United States (us)
This is great. But I have (perhaps) a stupid question. When you use the Variant for the lookup, how do you retrieve the recordref of the field?

I tried if form.runmodal(var,0) = action::lookupOK....but this didn't go anywhere. Version 2009R2.

Help?


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC + 1 hour [ DST ]


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum


Search for:
Jump to: