Automations

Alva1Alva1 Member Posts: 24
Hi

I would like to develop a codeunit using Automations, (want to write my own outlook int. codeunit)but i dunno how to use them??
well i do know the basic stuff but that's it!(i did create one codeunit that works with Ms word but it's very simple)
If somebody has some good tips, links or even books, please let me know.

Alva
Best regards

Alva1

Answers

  • garakgarak Member Posts: 3,263
    Thats the same principle.

    Here one of my little old example (example shows how to create Outlook contacts from NAV Contacts <- old solution for an Customer with NAV 2.xx) (Int = Table 5000, Kont = Table 5002 (Interesent / Contact))
    CreateAutomation()
    //Create the automation
    
    CREATE(OLApp);
    OLCont := OLApp.CreateItem(2);
                            {0 = E-Mail
                             1 = App.
                             2 = Contactperson
                             3 = Task
                             4 = Logbookitem
                             5 = Note
                             6 = Discussion }
    AutomCreated := TRUE;
    
    ------
    CreateOLContact(IntNo : Code[20];KontNo : Code[20];AlsoPersons : Boolean)
    
    IF (IntNo = '') THEN
      EXIT;
    
    Int.GET(IntNo);
    
    Window.OPEN(Text0002);
    
    IF (KontNo = '') THEN BEGIN  //aufruf aus der Interessentenübersicht heraus
      FillArray(IntNo,''); //First create the Interessent
      CreateOLConts(FieldArray);
    END;
    
    IF (AlsoPersons) THEN BEGIN
      IF (KontNo <> '') THEN BEGIN
        Kont.RESET;
        Kont.SETRANGE("Interessentennr.",Int."Nr.");
        Kont.SETRANGE("Nr.",KontNo);
      END ELSE BEGIN
        Kont.RESET;
        Kont.SETRANGE("Interessentennr.",Int."Nr.");
      END;
      counter := Kont.COUNT;
      i += 0;
      IF Kont.FIND('-') THEN BEGIN
        REPEAT
          i += 1;
          Window.UPDATE(1,ROUND(i*100/counter*100,1));
          FillArray(IntNo,Kont."Nr.");
          CreateOLConts(FieldArray);
        UNTIL Kont.NEXT = 0;
      END;
    END;
    Window.CLOSE();
    //OLCont.display;
    ClearAutomation();
    
    
    FillArray(IntNo : Code[20];KontNo : Code[20])
    CLEAR(FieldArray);
    IF (KontNo = '') THEN BEGIN
      Int.GET(IntNo);
      FieldArray[1] := '0';
      FieldArray[2] := Int.Name;
      FieldArray[3] := Int.Adresse;
      FieldArray[4] := Int.Ort;
      FieldArray[5] := Int. "PLZ Code";
      FieldArray[6] := Int."Telefonnr.";
      FieldArray[7] := Int."Faxnr.";
      FieldArray[8] := Int."E-Mail";
      FieldArray[9] := Int.Homepage;
      FieldArray[10] := Int."Nr.";
    END ELSE BEGIN
      Kont.GET(IntNo,KontNo);
      Int.GET(IntNo);
      FieldArray[1]  := '1';
      FieldArray[2] := Int.Name;
      FieldArray[3] := Int.Adresse;
      FieldArray[4] := Int.Ort;
      FieldArray[5] := Int. "PLZ Code";
      FieldArray[6]  := Kont.Name;
      FieldArray[7]  := Kont.Vorname;
      FieldArray[8]  := Kont."Telefonnr. Durchwahl";
      FieldArray[9] := Int.Homepage;
      FieldArray[10] := Int."Nr.";
      FieldArray[11] := Kont."Nr.";
      FieldArray[12]  := Kont."Mobile Telefonnr.";
      FieldArray[13]  := Kont."E-Mail";
      FieldArray[14]  := Kont."Faxnr. Durchwahl";
      FieldArray[15]  := Kont."Privat Telefonnr.";
      FieldArray[16]  := FORMAT(Kont.Geburtstag);
      IF (Kont.Funktion <> '') THEN BEGIN
        IF Funkt.GET(Kont.Funktion) THEN
          FieldArray[17]  := Funkt.Beschreibung;
      END;
      FieldArray[18] := Kont.Adresse;
      FieldArray[19] := Kont.Ort;
      FieldArray[20] := Kont."PLZ Code";
    END;
    -----
    
    
    CreateOLConts(VAR FieldArray : ARRAY [20] OF Text[100])
    
    IF NOT AutomCreated THEN
      CreateAutomation();
    
    IF (FindOLContact('Int:' + FieldArray[10] + ';Kont:' + FieldArray[11]) <> 0) THEN
      EXIT;
    
    FillFields(FieldArray);
    
    FillFields(VAR FieldArray : ARRAY [20] OF Text[100])
    CASE FieldArray[1] OF
      '0':
        BEGIN
          OLCont.CompanyName := FieldArray[2];
          OLCont.BusinessAddressStreet := FieldArray[3];
          OLCont.BusinessAddressCity := FieldArray[4];
          OLCont.BusinessAddressPostalCode := FieldArray[5];
          OLCont.BusinessTelephoneNumber := FieldArray[6];
          OLCont.BusinessFaxNumber := FieldArray[7];
          OLCont.Email1Address := FieldArray[8];
          OLCont.BusinessHomePage := FieldArray[9];
          OLCont.CustomerID := 'Int:' + FieldArray[10] + ';Kont:';
          OLCont.Categories := 'LSCP';
          OLCont.Save;
        END;
      '1':
        BEGIN
          OLCont.CompanyName := FieldArray[2];
          OLCont.BusinessAddressStreet := FieldArray[3];
          OLCont.BusinessAddressCity := FieldArray[4];
          OLCont.BusinessAddressPostalCode := FieldArray[5];
          OLCont.LastName := FieldArray[6];
          OLCont.FirstName := FieldArray[7];
          OLCont.BusinessTelephoneNumber := FieldArray[8];
          OLCont.BusinessHomePage := FieldArray[9];
          OLCont.CustomerID := 'Int:' + FieldArray[10] + ';Kont:' + FieldArray[11];
          OLCont.MobileTelephoneNumber := FieldArray[12];
          OLCont.Email1Address := FieldArray[13];
          OLCont.BusinessFaxNumber := FieldArray[14];
          OLCont.HomeTelephoneNumber := FieldArray[15];
          IF (FieldArray[16] <> '') THEN BEGIN
            EVALUATE(Birth,FieldArray[16]);
            OLCont.Birthday := Birth;
          END;
          OLCont.JobTitle := FieldArray[17];
          OLCont.HomeAddressStreet := FieldArray[18];
          OLCont.HomeAddressCity := FieldArray[19];
          OLCont.HomeAddressPostalCode := FieldArray[20];
          OLCont.Categories := 'LSCP';
          OLCont.Save;
        END;
    END;
    

    Hope understandeble. It's very easy. It's the same like in Word or Excel or PowerPoint or MS Mappoint .....

    Regards
    Do you make it right, it works too!
  • Alva1Alva1 Member Posts: 24
    Thank u very much garak for your example it sure will help me a lot!!!!
    i think that is exactly what i need i'll give it a try!!!

    but now changing topic, i would like to know how you learn to along with the automations declarations,
    just practice or did u found ebook or bought books related to this topic?????

    Best regards


    Alva1
    Best regards

    Alva1
  • SogSog Member Posts: 1,023
    You can buy (e-)books offcourse. But I've learned automation through VBA. Creating macro's and such.
    It's easier in the VBA, .Net development enviroment because you always get a list of all the possible options from an object.
    Thus making exploring a lot easier then the C/AL enviroment.
    And offcourse, when I got stuck there was always the internet with a lot of examples.
    |Pressing F1 is so much faster than opening your browser|
    |To-Increase|
  • Alva1Alva1 Member Posts: 24
    That sounds really cool, i really don't have experienci in VB or VBA
    but ill think that's the next thing i need to learn!!
    can i create in VBA applications to automate Navision???
    Like when Nav start up wait 40 seconds and automatically open a menu and choose an option???
    i need this for example when i restart the server or the server needs to be restarted late at night!

    Greetings

    Alva1
    Best regards

    Alva1
  • garakgarak Member Posts: 3,263
    for me learning by doing.
    If i have a complex claim (for example in ecxel) i start a macro and do this what navision should do. Than i take a look into the VBA code and do the same in NAV.
    Also helps me the chm (Helpfiles) of VBA. For example in the VBAXL10.CHM is all explained (in VBA but easy to transfer to NAV). You m,ust only know, that every bough on the tree (see picture to understand what i mean) is a new Automation Variable.


    Regards
    Do you make it right, it works too!
Sign In or Register to comment.