Issues when upploading a document to a datasource/Environment with required attributes

Hi!

I’m trying to add a document to a datasource, but when I try and add it using aaApi_CreateDocument() it fails…

The reason is that there are some attributes are required or requires a value != null and I guess they don’t have a default value set.

Is there a way to upload a new document and set required attributes simultainously?

 

If I try and add a document manually without using a wizard I get the same issue, “Last Error [ 58116 ] Error creating new document. Required field has no value.” so the user is forced to use the wizard.

Any help would be greatly appreciated!

/Per

Parents
  • It would really be helpful if you posted a code snippet to show how you are using the function. I would encourage anyone with "problems" with code, to post code snippets to help others help you as it really doesn't help to say "something doesn't work, why is that?" Please don't take this personally, as it is very common, and we all do it at some point and to some degree.

    I suspect that the environment for the folder where you are trying to create a document is configured to create an attribute row when a document is created and that you are not accounting for that in your code. What are you are specifying the value for the parameter "ulFlags"?

    If you haven't already done so, try setting this parameter to AADMSDOCCREF_NO_ATTR_RECORD and see if that "fixes" your problem. As the developer, you need to make sure that you follow the intention of the various datasource and user settings as not all of them (most are not) enforced at the API level as that is what makes using the API functions so powerful as you can "override" default behavior (but not security and some datasource or user settings).

    To answer your question about "is it possible", no, but you can make it look like it is as that is what the Wizard is doing.  It creates the document first, but has the information that it needs to create the attribute row, so after creating the document without an attribute row, it then creates the attribute row using the values that the user specified in the wizard (and it probably first validated that those values would work).  You probably should do the same in your code.  Make sure that you have (or know) any required attribute values before creating the document so that you (the developer) don't break the intention of the PW Administrator of not having documents created without an attribute row.

    Answer Verified By: Per Bodin - AEC AB 

  • Hi Dan!

    Thank you!! Perfect, that was exactly what I was looking for, worked like a charm. We’re now able to upload files even if attributes are required.

    I’d gone the long way and tried collected all the attribute-definitions and all their properties to check if they had any required parameters and was looking for a way to set those at upload time. But, now I can upload without setting them, with the option to use my code to identify and warn and possibly fill out the required values afterwards if they are available.

    Of course I should have supplied a snippet as you say, I was just a bit frustrated at the time an just threw a question out there to see if someone could help, for reference here is some code: 
    Working in both c++ and writing a wrapper in c# but here’s a snip of the c++ bit with the magic attribute hardcoded.

    bool bOK = aaApi_CreateDocument(&docID, _CurrentProjectId, 0, 0, AADMS_ITYPE, lngAppID, NULL, lngWorkSpaceID, bstrTemplateFile, bstrFileNameWithExtension, bstrName, bstrComments, NULL, FALSE, AADMSDOCCREF_NO_ATTR_RECORD, strWorkingDir, _MAX_PATH - 1, &AttributeId);

    Thanks again!!!
  • Darius,

    My apologizes, when I teach the ProjectWise SDK class, C++ is used and aaApi_CreateEnvAttr() is used in the exercises.

    I see that aaApi_CreateEnvAttr() isn't in MostOfDavesClasses, and that he does use aaApi_CreateLinkDataAndLink().  

    Here's some C# code that I have used to create attribute rows using aaApi_CreateLinkDataAndLink():

                    // create the new link row
                    int iLinkColId = 0;
                    StringBuilder sbVal = new StringBuilder(30);
    
                    if (!PWWrapper.aaApi_CreateLinkDataAndLink(iTableId, 1, curDoc.ProjectId, curDoc.DocumentId, ref iLinkColId, sbVal, sbVal.Capacity))
                    {
                        LogIt.WriteLogError("Could not create attributes for {0}", curDoc.Name);
                        LogIt.WriteLogOnlyPwError();
                        return false;
                    }
    

    I don't really see any difference in how you are calling that method, so please post your code for your class.method that creates the attribute rows and perhaps someone might be able to spot the issue you are having.

    And re-reading your post, I'm wondering if the ProjectWise Environment has Document Coding enabled?  Does it?

  • Hi Dan,

    Thank you for help.

    I have imported aaApi_CreateEnvAttr function to Most of Dave classes, but still got the same error. 

    System.Text.StringBuilder sbworkFile2 = new System.Text.StringBuilder(30);
    int lAttrColId = 0;
    int lAttrFileId = 0;
    PWWrapper._AAEALINKAGE aAEALINKAGE = new PWWrapper._AAEALINKAGE();
    PWWrapper._AADOC_ITEM aADOC_ITEM = new PWWrapper._AADOC_ITEM();
    aADOC_ITEM.lDocumentId = newdocId;
    aADOC_ITEM.lProjectId = projId;
    aAEALINKAGE.documentId = aADOC_ITEM;
    aAEALINKAGE.lEnvironmentId = envId;
    aAEALINKAGE.lLinkageType = 1;

    bool createlink1 = PWWrapper.aaApi_CreateEnvAttr(lTableId, aAEALINKAGE, out lAttrFileId);
    string error11 = PWWrapper.aaApi_GetLastErrorDetail();

    bool createlink = PWWrapper.aaApi_CreateLinkDataAndLink(lTableId, 1, projId, newdocId,
    ref lAttrColId, sbworkFile2, sbworkFile2.Capacity);
    string error1 = PWWrapper.aaApi_GetLastErrorDetail();

    In both methods it gives the same error "Code is already in use", It is not clear what code.

    I can create 4 files from my 6 list, but 2 of them have this problem. I tried to create exactly the same with wizard and it works.

    Yes Document coding is eabled.

    Thank you

    Darius

  • Update.

    I have found wrong set of value to file serial number. Fixed it and it started to work.

    Thank you for very big Help Dan, appreciate it.

    Best regards

    Darius

  • I'm happy to hear that you have your code working. 

    I'm wondering how you are determining the serial number, assuming that this serial number is part of a ProjectWise Document Code.  Hopefully, you took a look at using aaApi_CodeSerialGenerate(). 

    I suppose that you could "manually" determine the "next" or "first available" serial number yourself, but that sounds like more effort than necessary and probably generates more "over the wire" traffic.  Keep in mind that users can reserve Document Codes in advance, so if you are trying to determine the "next" or "first available" via your own code, you may overlook what's been reserved and those values won't work until they are released by the user, leaving your code to possibly fail and the reason not entirely clear.

    If you aren't familiar with ProjectWise Document Coding, I would recommend reading up on it in all of the various help files (Admin, Explorer and SDK), as well as experimenting with reserving documents codes.

  • Hi,

    No, I do not use aaApi_CodeSerialGenerate() as all this situation is more complicated.

    I already have generated document on other (3rd party) DMS and I need to add/update file to PW.

    It can be the situation when the document is generated in 3rd party DMS, but not available on PW.

    This I will need to manage as well by informing user about the problems.

    Best regards

    Darius

Reply Children
No Data