Returning a Parameter when using webservices

attardcattardc Member Posts: 97
edited 2012-06-21 in NAV Three Tier
I'm using Dynamics NAV webservices to allow users to create contacts and related comments via a web interface.

Is there a way that when the Contact is created (when calling the Create Service through Visual Studio) NAV webservices return the Contact No. (which is assigned automatically with the NAV INSERT) to the Visual Studio application so that then they can save the comments linked to this contact No.?

Currently we have to create the contact, go to this newly created contact and then add the comments, in order to be able to have the Contact No. We would like to reduce this to a 1 step/1 screen process if necessary!

thanks in advance for your help!

regards

Christabel

Comments

  • koubekkoubek Member Posts: 84
    Hi Christabel,

    You receive automatically contact no. when calling "Create". Here is a simple example:
    string salesOrderNo = "";
    
    SalesOrder so = new SalesOrder();
    
    ClientHeadWs.Create(ref so);
    salesOrderNo = so.No;
    
  • thegunzothegunzo Member Posts: 274
    With a published codeunit you can write a function to create both the contact and attach the comment or a note. You can place the comment in a bigtext variable. Here is an example of how you write the bigtext variable to the comment table or to a note.
    LF[1] := 10;
    
    CASE SignSetup."Web Comment Stored" OF
      SignSetup."Web Comment Stored"::"In Comment Lines":
        WITH CommentLine DO BEGIN
          RESET;
          SETRANGE("Table ID",DATABASE::"SKYRR Signer Queue");
          SETRANGE("Entry No.",Queue2."Entry No.");
          IF FINDLAST THEN
            NextLineNo := "Line No." + 10000
          ELSE
            NextLineNo := 10000;
    
          INIT;
          "Table ID" := DATABASE::"SKYRR Signer Queue";
          "Entry No." := Queue2."Entry No.";
          "Line No." := NextLineNo;
          Date := TODAY;
          BigComment.GETSUBTEXT(Comment,1,MAXSTRLEN(Comment));
          IF STRPOS(Comment,LF) > 0 THEN BEGIN
            Comment := COPYSTR(Comment,1,STRPOS(Comment,LF) - 1);
            ReadPos := ReadPos + STRLEN(Comment) + 1;
          END ELSE BEGIN
            Tools.RepairLineEnd(Comment);
            ReadPos := ReadPos + STRLEN(Comment);
          END;
          "User ID" := CurrentUserID;
          INSERT;
          NextLineNo := NextLineNo + 10000;
          
          Date := 0D;
          WHILE BigComment.LENGTH > ReadPos DO BEGIN
            "Line No." := NextLineNo;
            BigComment.GETSUBTEXT(Comment,ReadPos + 1,MAXSTRLEN(Comment));
            IF STRPOS(Comment,LF) > 0 THEN BEGIN
              Comment := COPYSTR(Comment,1,STRPOS(Comment,LF) - 1);
              ReadPos := ReadPos + STRLEN(Comment) + 1;
            END ELSE BEGIN
              Tools.RepairLineEnd(Comment);
              ReadPos := ReadPos + STRLEN(Comment);
            END;
            INSERT;
            NextLineNo := NextLineNo + 10000;
          END;
    
        END;
      SignSetup."Web Comment Stored"::"In Fact Box Notes":
        BEGIN
          ServerTempFileName := ThreeTierMgt.ServerTempFileName('','');
          StreamWriter := ServerFile.CreateText(ServerTempFileName);
          ReadPos := 0;
          WHILE ReadPos < BigComment.LENGTH DO BEGIN
            BigComment.GETSUBTEXT(CommentText,ReadPos + 1,MAXSTRLEN(CommentText));
            ReadPos := ReadPos + STRLEN(CommentText);
            StreamWriter.Write(CommentText);
          END;
          StreamWriter.Close;
    
          RecordLink.GET(Queue2.ADDLINK('',Queue2.TABLECAPTION));
          RecordLink.Type := RecordLink.Type::Note;
          RecordLink."User ID" := CurrentUserID;
          RecordLink.Note.CREATEOUTSTREAM(OutStr);
          Encoding := Encoding.UTF8;
          BinaryWriter := BinaryWriter.BinaryWriter(OutStr,Encoding);
          BinaryWriter.Write(ServerFile.ReadAllText(ServerTempFileName));
          RecordLink.MODIFY;
    
          ServerFile.Delete(ServerTempFileName);
        END;
    END;
    

    and the RepariLineEnd is
    RepairLineEnd(VAR inpara : Text[1024]) UsedStringLength : Integer
    IF STRPOS(inpara,' ') > 0 THEN
      WHILE COPYSTR(inpara,STRLEN(inpara),1) <> ' ' DO
        inpara := COPYSTR(inpara,1,STRLEN(inpara) - 1);
    
    ________________________________
    Gunnar Gestsson
    Microsoft Certified IT Professional
    Dynamics NAV MVP
    http://www.dynamics.is
    http://Objects4NAV.com
  • koubekkoubek Member Posts: 84
    Or if you want to import complex data you can use importing by passing a XmlPort into a function of the codeunit. You have to implicitly call import and later filter exported data. As this XmlPort data structure appears in .NET as a class with subclasses this method seems to be really powerful (you can send all data in one transaction, after processing the data they can be simply sent back in a actualized form). Try to import complex data in this way.
Sign In or Register to comment.