Trying to create my first codeunit

ZiqXxZiqXx Member Posts: 24
I am following the Hello World Navision Tutorial on MSDN and I have added this code to my codeunit:
CREATE(MQBus);
CREATE(CC2);
CREATE (XMLDom);
CC2.AddBusAdapter(MQBus,1);
MQBus.OpenReceiveQueue('.\toNavision',0,0);

CC2::MessageReceived(VAR InMessage : Automation "''.IDISPATCH")

// get the message
InMsg := InMessage;
InS := InMsg.GetStream();

// load the message into an XML document and find a node
XMLDom.load (InS);
XMLNode := XMLDom.selectSingleNode ('string');

// open the response queue and create a new message
MQBus.OpenWriteQueue('.\fromNavision',0,0);
OutMsg := CC2.CreateoutMessage('Message queue://.\fromNavision');
OutS := OutMsg.GetStream();

// build the contents of your message
XMLNode.text := UPPERCASE (XMLNode.text);

// fill the message and send it
OutS.WRITE(XMLDom.xml);
OutMsg.Send(0);

I have also created these variables

But when I try to save the codeunit I get an error saying:
"Not an allowed option"

Does any one here know what I am doing wrong ?

Comments

  • DenSterDenSter Member Posts: 8,307
    It's this line of code:
    CC2::MessageReceived(VAR InMessage : Automation "''.IDISPATCH")
    
    This is actually not supposed to be a statement, but it's an event.

    Go to your CC2 global and open the properties page. Set the WithEvents property to Yes. When you close the globals window, you should see a new event trigger called "CC2::MessageReceived", which fires each time a message is received into your communication component. Then move the code underneath your statement into the event trigger that Navision created.

    If Navision doesn't add the trigger, you need to remove the CC2 variable, close and save your codeunit, and then add the variable again, and don't forget to set the WithEvents property.

    By the way, it says 'not a valid option' because two colons is the notation to enumerate option values in C/AL code.
  • ZiqXxZiqXx Member Posts: 24
    Thank you so much, this was great. I am trying to learn how to do these codeunits and working with Navision that was great help. Much appriciated.
  • ZiqXxZiqXx Member Posts: 24
    Hello I have been trying to follow the Hello World Navision guide on MSDN, http://msdn.microsoft.com/library/defau ... vision.asp - And I have done everything but when I try to send to the queue's I get timed out, and when I restart the machine I get a lot of these message in my event viewer:
    The description for Event ID ( 109 ) in Source ( NBX-NAVISION-CLASSIC ) cannot be found. The local computer may not have the necessary registry information or message DLL files to display messages from a remote computer. You may be able to use the /AUXSOURCE= flag to retrieve this description; see Help and Support for details. The following information is part of the event: The network is not functioning correctly. A 'packet' has been corrupted (a checksum error).
    
    This error indicates that the network is not completely reliable. Please note how often this type of error occurs in the network. Contact your system manager if yo.
    
    ---------------------------------------------------------------------------------
    
    The description for Event ID ( 109 ) in Source ( NBX-NAVISION-CLASSIC ) cannot be found. The local computer may not have the necessary registry information or message DLL files to display messages from a remote computer. You may be able to use the /AUXSOURCE= flag to retrieve this description; see Help and Support for details. The following information is part of the event: The Navision Application Server NBX-NAVISION-CLASSIC could not initialize properly.
    The server will attempt to initialize every 30 seconds until this is successful.
    
    

    Does anyone here reconize these error messages ?
  • ckndr47ckndr47 Member Posts: 100
    Have you configured, ur NAS?
  • Miklos_HollenderMiklos_Hollender Member Posts: 1,598
    http://mibuso.com/dlinfo.asp?FileID=608

    Use it as an example, or maybe you can use it without coding, as it is.
Sign In or Register to comment.