mibuso.com

Microsoft Business Solutions online community
It is currently Mon May 20, 2013 3:19 pm

All times are UTC + 1 hour [ DST ]




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: Managing a function called from both OnValidate and OnRename
PostPosted: Fri Jun 29, 2012 7:21 pm 
Offline

Joined: Thu Oct 27, 2011 7:38 pm
Posts: 82
Location: Lacey, Washington
Country: United States (us)
I am using table 5717 item Cross Reference with the following code:

Code: Select all
----------------------------------
OnRename()
----------------------------------
message('From rename');
MyFunction;

-----------------------------------
Cross-Reference No. - OnValidate()
-----------------------------------
message('From validate');
MyFunction;

------------------------------------
MyFunction()
------------------------------------
message('called myfunction');


If I go to an existing record in the table, edit the Cross-Reference No. field, then press the down arrow, the system returns the following:

Quote:
Do you want to rename the record?
from validate
called myfunction
from rename
called myfunction


In a situation like this, how do I minimize calling MyFunction correctly? This is my hack so far:

Form 5721 Item Cross Reference Entries
Code: Select all
-----------------------------------
Form - OnModifyRecord() : Boolean
-----------------------------------
IF "Cross-Reference No." <> xRec."Cross-Reference No." THEN
     AlreadyCalled := TRUE;


Table 5715 Item Cross Reference
Code: Select all
----------------------------------
OnRename()
----------------------------------
message('From rename');
IF NOT AlreadyCalled THEN
    MyFunction;
AlreadyCalled := FALSE;

-----------------------------------
Cross-Reference No. - OnValidate()
-----------------------------------
message('From validate');
MyFunction;

------------------------------------
MyFunction()
------------------------------------
message('called myfunction');



Is this the correct way of doing things?

_________________
Michael Hollinger
Systems Analyst


Top
 Profile E-mail  
 
 Post subject: Re: Managing a function called from both OnValidate and OnRe
PostPosted: Sat Jun 30, 2012 8:25 am 
Offline

Joined: Fri Dec 03, 2010 5:20 pm
Posts: 32
Location: Pune
Country: India (in)
Hi,

When you are Creating Function MyFunction Create it with parameter

MyFunction(CalledFrom)
if CalledFrom='FromValidate' then
//Dovalidate related actions
if CalledFrom='FromRename' then
// doRename related action

while calling this function call with respective parameters

hope this helps.


Top
 Profile E-mail  
 
 Post subject: Re: Managing a function called from both OnValidate and OnRe
PostPosted: Sat Jun 30, 2012 8:40 am 
Offline

Joined: Sat Aug 08, 2009 6:28 am
Posts: 158
Location: gujarat
Country: India (in)
Hi,

If your primary Key has only field "Cross Reference No." Then Remove call of myFunction From OnRename Record or Onvlaidate.
Because whenever you call Onvalidate automatically OnRename will be called

_________________
Uday Mer | MS Dynamics NAV Techno-Functional Consultant


Top
 Profile E-mail  
 
 Post subject: Re: Managing a function called from both OnValidate and OnRe
PostPosted: Mon Jul 02, 2012 7:56 pm 
Offline

Joined: Thu Oct 27, 2011 7:38 pm
Posts: 82
Location: Lacey, Washington
Country: United States (us)
Yashojit Pandhare, udayrmer, thanks for the responses. However, I have some complications to add:


1. Let's say I want the logic in MyFunction to run only during OnValidate calls. If I perform "Item Cross Reference".Rename() from code, I don't get an OnValidate call!

2. Let's say i want the logic in MyFunction to run only during OnRename calls. If I perform "VALIDATE("Cross Reference No.",'123456') from code, I don't get an OnRename call!

I think I need to do something like this:

Code: Select all
----------------------------------
OnRename()
----------------------------------
MyFunction(FALSE);

----------------------------------
Cross-Reference No. - OnValidate()
----------------------------------
MyFunction(TRUE);

----------------------------------
MyFunction(CalledFromValidate : Boolean)
----------------------------------
IF CalledFromValidate OR AllowFunction THEN BEGIN
     AllowFunction := FALSE;  //Reset the variable
     // Perform Logic
END;


With this setup, I just need to set AllowFunction to TRUE prior to explicitly calling a Rename.

_________________
Michael Hollinger
Systems Analyst


Top
 Profile E-mail  
 
 Post subject: Re: Managing a function called from both OnValidate and OnRe
PostPosted: Tue Jul 03, 2012 7:33 am 
Offline

Joined: Sat Aug 08, 2009 6:28 am
Posts: 158
Location: gujarat
Country: India (in)
Can you tell me in myFunction code get executed is same for both called from OnRename & OnValidate ?

_________________
Uday Mer | MS Dynamics NAV Techno-Functional Consultant


Top
 Profile E-mail  
 
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: abhi1901, Exabot [Bot], Google [Bot] and 24 guests


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: