Jump to content

Creating User-Defined Functions


Recommended Posts

I am trying to create a user defined function (rules manual p64). I created a new node and function. I used the example in the book but when i select the the function from the "Building Blocks" into a rule and try to validate....I get the message: Reference Error:Dateyyyymmdd is not defined. How can it not be defined....after all, it is in the "Building Blocks". As my mother would always say to me Where did I go Wrong?

 

Geodine.js

Geodine = new Object;

Geodine.Dateyyyymmdd = function()

{

var thedate = new Date();

return FormatDate(thedate, "yyyymmdd");

}

Geodine.Dateyyyymmdd.description = "Return Date in the yyyymmdd format";

Geodine.Dateyyyymmdd.syntax ="Dateyyyymmdd()";

Link to comment
Share on other sites

Dan, Thanks for the response. I tried your changes, but I get the same error message. I have even tried to comment out the description and syntax lines as it said in the book. but same error. It won't validate.

 

Geodine = new Object;

Geodine.Dateyyyymmdd = function()

{

var thedate = new Date();

return FormatDate(thedate, "yyyymmdd");

}

Geodine.Dateyyyymmdd.description = "Return Date in the yyyymmdd format";

Geodine.Dateyyyymmdd.syntax ="Geodine.Dateyyyymmdd()";

Link to comment
Share on other sites

Hmm. I copied the syntax above into a .js file in my plug-ins folder, and it showed up in the Building Blocks for me. I typed "return " and then clicked "Insert" and the result was this rule, which validated just fine (result was "20100128"):

return Geodine.Dateyyyymmdd()

You may need to close and re-open the Rules dialog for the changes to the .js plug-in file to take effect. Can you post the syntax of your actual rule, not just the plug-in syntax?

Link to comment
Share on other sites

Thanks Dan,

return Geodine.Dateyyyymmdd()

fixed it. But why when I insert it from the building blocksdo I only get

return Dateyyyymmdd()

Did you change the last line of the .js file as I suggested?

The last line should be:

Geodine.Dateyyyymmdd.syntax = "Geodine.Dateyyyymmdd()";

You're declaring the function as a member of the global Geodine object, not as a global function itself.

And like I said, you may need to close and re-open the Rules dialog for the changes to the .js plug-in file to take effect.

Link to comment
Share on other sites

Dan,

I did due all yo suggested, and it now works.

 

.js file

 

Geodine = new Object;

Geodine.Dateyyyymmdd = function()

{

var thedate = new Date();

return FormatDate(thedate, "yyyymmdd");

}

Geodine.Dateyyyymmdd.description = "Return Date in the yyyymmdd format";

Geodine.Dateyyyymmdd.syntax ="Geodine.Dateyyyymmdd()";

 

 

What fixed it was changeing the rule to :

 

return Geodine.Dateyyyymmdd()

 

I was just trying now to understand why when you double click it in the building blocks it returns:

 

return Dateyyyymmdd()

 

instead of

 

return Geodine.Dateyyyymmdd()

 

Thanks again for all your help.

George

 

PS...... Is Doug Cogan still around, or Lauren Nakoney?

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...