Create document version for document already checked-out

Is there a function to create a new version of a document on check-in?

Parents
  • Yes, take a look at aaApi_DocumentCheckInActionDlg2().

    You may already be aware of the "problem" of finding what you are looking for in the ProjectWise SDK documentation.  A "trick" I have covered before, and cover in the ProjectWise SDK training that I teach, is to be "clever" on how you search for your item of interest.  Unfortunately, it's a bit of "you don't know what you don't know" as well as "words get in the way" type of problem, particularly if your native language is not English!

    For example, to find the function to MOVE a FOLDER, it isn't clear that the key word here is PARENT.  To move a folder, you need to change a folder's parent folder.

    That function is aaApi_SetParentProject().  And of course, in this context and this instance, a folder is called a project.  

    Another example, is how I found the function to create a version on check in, to answer the question in this post.

    What I did was to search the *.h and *.fdf files delivered with the SDK for text that I thought might be related to what I was looking for.

    To find the above function I used this search in Notepad++:

    Then by browsing through the results I noticed this:

    And clicking on line 2553 I then see this:

    Then by looking at the documentation in the help file, I found a function that will allow a new version to be created on check in!

    HTHs

Reply
  • Yes, take a look at aaApi_DocumentCheckInActionDlg2().

    You may already be aware of the "problem" of finding what you are looking for in the ProjectWise SDK documentation.  A "trick" I have covered before, and cover in the ProjectWise SDK training that I teach, is to be "clever" on how you search for your item of interest.  Unfortunately, it's a bit of "you don't know what you don't know" as well as "words get in the way" type of problem, particularly if your native language is not English!

    For example, to find the function to MOVE a FOLDER, it isn't clear that the key word here is PARENT.  To move a folder, you need to change a folder's parent folder.

    That function is aaApi_SetParentProject().  And of course, in this context and this instance, a folder is called a project.  

    Another example, is how I found the function to create a version on check in, to answer the question in this post.

    What I did was to search the *.h and *.fdf files delivered with the SDK for text that I thought might be related to what I was looking for.

    To find the above function I used this search in Notepad++:

    Then by browsing through the results I noticed this:

    And clicking on line 2553 I then see this:

    Then by looking at the documentation in the help file, I found a function that will allow a new version to be created on check in!

    HTHs

Children
  • Thanks Dan, but I can't use a dialog in this case. I am trying to use aaApi_NewDocumentVersion but it requires the document to be checked in. But if I can't update the Server before creating a new version so I am trying to free the document, create the new version and check-out the document again with aaApi_FetchDocumentFromServer and flags AADMS_DOCFETCH_CHECKOUT | AADMS_DOCFETCH_IGNORE_UPTODATECOPY.

    When the file gets checked-out it overwrites the local copy. I have tried using AADMS_DOCFETCH_LOCK but I can't specify a working folder.

  • Oh, no dialog.

    I think your logic is OK, but you will have to move or copy the file that you have in your working directory so that you can overwrite the file that will be checked out, before you check it in again.

    Or, you could save a copy of the file somewhere safe, free the document, create a new version and then replace the newly created document version's file with one of the aaApi_ChangeDocumentFileX() functions.

    I have had problems with replacing files on documents in the past, and my workaround was to first remove the file, and then add the file, but try the "change doc file" functions first to see if they do what you need.

    FWIW, this is another case of not knowing what to look for.  I want to replace a document's file, but the functions that will do that are named with "change".  And again I searched the *.h and *.fdf for the search string replace.*file and found this:

    Answer Verified By: Kevin Cox 

  • Amazing work! Solved an unresolved old past issue.

    Now I need to get my head around Flat Sets.

  • Hi Dan, I have a issue with aaApi_DocumentCheckInActionDlg2.  

    as I test, I check in  one file  in pwc for testing, then I call  aaApi_DocumentCheckInActionDlg2, the form show up, looks all right. but  click any button, it not work fine and get a crash.  do u have some sample for this api  or any idea? thx.

    C++  code like below:


    AADOC_ITEM ai[1];
    ai[0].lProjectId = lpDocItems->lplProjectIds[lDocIdx];
    ai[0].lDocumentId= lpDocItems->lplDocumentIds[lDocIdx];
    BOOL nVer = false;
    LPWSTR strcom=L"D";

    aaApi_DocumentCheckInActionDlg2(NULL, L"DDD", 0, 0, ai, 1, &nVer, strcom, 2000);


    C# code like below:

    [DllImport("DMAWIN.DLL", CharSet = CharSet.Unicode)]
    public static extern int aaApi_DocumentCheckInActionDlg(IntPtr hWndParent, string strTitle, uint flags, IntPtr pDocuments, int count, ref bool pNewVersion, StringBuilder pComment, int commentLength);


    [DllImport("DMAWIN.DLL", CharSet = CharSet.Unicode)]
    public static extern int aaApi_DisplayDocumentCheckInActionDlg(
    IntPtr hWndParent,
    string lpctstrTitle,
    uint flags,
    int count,
    IntPtr pDocuments,
    ref Boolean pNewVersion,
    StringBuilder pComment,
    int commentLength);


    [DllImport("DMAWIN.DLL", CharSet = CharSet.Unicode)]
    public static extern int aaApi_DocumentCheckInActionDlg2(
    IntPtr hWndParent,
    string strTitle,
    uint flags,
    uint checkinFlags,
    IntPtr pDocuments,
    int count,
    ref bool pNewVersion,
    StringBuilder pComment,
    int commentLength
    );

    DocFun.AADOC_ITEM[] items = new DocFun.AADOC_ITEM[1];

    items[0].lProjectId = 2153;
    items[0].lDocumentId = 13;

    IntPtr iptdoc = MarshalHelper.IntPtrFromStuctArray<DocFun.AADOC_ITEM>(items);
    StringBuilder stCom = new StringBuilder();
    stCom.Append("xx");
    string title = "YY";

    Boolean bVer =false ;

    int t=DocFun.aaApi_DocumentCheckInActionDlg2(Process.GetCurrentProcess().Handle, title, 0, 0, iptdoc, 1, ref bVer, stCom, 4096);

  • My guess is your C++ code is crashing because you did not allocate enough memory for the second last parameter in aaApi_DocumentCheckInActionDlg2().

    You set strcom to just one character, but you tell the function that the allocated buffer length is 2000.

    Try allocating a string buffer large enough for you needs, and pass that length to the function and see if that fixes your problem.

    Keep in mind that "strings" in C and C++ can vary in their actual "type" (arrays of characters vs. an object).  In C+, "strings" are immutable and are always objects, and as you are showing, StringBuilder is a good choice when you want the object to behave like a buffer.

    I didn't check your C# code.  See if you can get the C++ code to work first.