Rename Document file with a custom attribute

Hi,

I have a custom attribute called file ID and it is uniqe, I wont to use this attribute's value to be as the name of document file. once user clike ssave in properties page.

 

I used "AAHOOK_UPDATE_LINK_DATA"

LONG AAAPIHOOK  Hook_PreModifyDocument2

(

LONG *hookId*/,

LONG /*hookType*/,

AAPARAM         aParam1,

AAPARAM         aParam2,

AARESULT*       pResult

)

    {

   if (aParam2 !=  AAOPER_DOC_UPDATE_LINK_DATA)

   return AAHOOK_SUCCESS;

    LPAADOC_PARAM pProParam = (LPAADOC_PARAM)aParam1;


if (pProParam->lDocumentId != 0)

the problem is LPAADOC_PARAM dose not return the correct Document ID.

any Idea?

Regards

Ghazi

Parents
  • Ghazi, the filename is not an attribute (link data) property. It is a document property. You need to use ModifyDocument or ModifyDocument2 to change the filename. However, I do not know if this function also reaches out to the server and changes the actual filename. I hope it does, please test.
  • Dean, I know that. my question is i need to hook a costum attribute changes . and I sucess but the problem how to get document id.


    if i get Doc ID then I will use ModifyDocument.

    Regards
    Ghazi
  • Thanks for all of you , I resolved it and success getting Document ID, it was very simple

    AALINKDATA_HOOK_PARAM const* pDocParam = reinterpret_cast<AALINKDATA_HOOK_PARAM const*> (aParam1);
    lDocId = aaApi_GetDocumentId(0);
    iProjId = aaApi_GetProjectId(0);


    Regards
    Ghazi
  • Ghazi,

    I should warn you that the use of those two calls just happen to work and will probably work 99% of the time, but it is only because it is likely that ProjectWise has already put that information into the buffer that those calls are reading. (Check the documentation for the "proper" use of those calls).

    You can get the document and project ids that you need directly from what is being pass to your hook function and you can be sure that it is correct.

    In your hook, cast aParam1 something like this:

    LPAALINKDATA_HOOK_PARAM pParam = (LPAALINKDATA_HOOK_PARAM)aParam1;

    (You should also check what the value of aParam2 is for "defensive programming" so that you are only processing the operations that you know about. It is possible that additional processes could be added to a hook in the future. )

    Then these values should be available to you:

    pParam->lpLinkage->documentId.lProjectId

    pParam->lpLinkage->documentId.lDocumentId

    pParam->lAttributeRecordId

    HTHs
  • Hi Dan,

    As I mentioned earlier, see above, when I tried:
    LPAAEALINKAGE  lPLinkage = pDocParam->lpLinkage; //But can't get linkage. Don't know why?
    

    So I can't get the likage, let alone documentId, why?

    Thanks

    Wence

  • Wence,

    I would have to take a closer look at your code. Send me a private message and perhaps I can take a look.

    I suspect that you are casting aParam1 to something that it isn't. What you should cast aParam1 to is dependent upon the hook type. In your posting, you said that you were setting a hook for AAHOOK_UPDATE_LINK_DATA. Looking at the documentation for that hook id you can see that aParam1 is defined as a pointer to a structure, and there is a difference (as you probably know) between LPAALINKDATA_HOOK_PARAM and AALINKDTA_HOOK_PARAM.

    Also, if you are interested in the linkage, then you need to inspect the structure as it is defined as a union and its contents depend upon what type of linkage it is.
  • Hi Dan,

    Please check your private message.

    I think your casting way is the same as mine, we all got a pointer to AAHOOK_UPDATE_LINK_DATA. I tried to debug using your code. Still got the same error when tring to get the linkage. All other members are good, like ulMask, lTableId, lAttributeRecordId.

Reply Children
  • Yes, I get the same results. I'll try to find out an answer to the obvious question (is it a bug, or is the documentation wrong). I've used this hook before, but not for many years, so perhaps something has changed.
  • I believe the documentation for AAHOOK_UPDATE_LINK_DATA is incomplete. From notes I have in code that uses this hook, whenever the operation from aAparam2 is AAOPER_DOC_UPDATE_LINK_DATA, lpLinkage is not defined. This has also been my experience with it.


    As you've already found, the only way to get the Doc Id in this scenario is to use aaApi_SelectLinksByAttr and then aaApi_GetLinkNumericProperty.

  • Thanks Jeff! I think your solution is likely to be the best "workaround" until either the documentation is updated or the function changed to match the documentation.
  • Hi Jeff,

    Thanks for the value information.
    DocId = aaApi_GetDocumentId(0); works for a single document but it does not with multi.
    I tried using both functions aaApi_SelectLinksByAttr & aaApi_GetLinkNumericProperty but it does not work. would you share the correct way?

    Regards
    Ghazi
  • The hook AAHOOK_UPDATE_LINK_DATA will get called each time a document attribute sheet is updated. When you update multiple document attribute sheets in a single action, the hook will still get called for each, individually. The way I handle getting the document Id in the case of operation AAOPER_DOC_UPDATE_LINK_DATA in my post hook function is something like this:

    LONG AAAPIHOOK HookUpdateLinkData_Post (LONG hookId,LONG hookType,AAPARAM aParam1,AAPARAM aParam2,AARESULT* pResult)

    {

    LPAALINKDATA_HOOK_PARAM pParam = (LPAALINKDATA_HOOK_PARAM)aParam1;

    switch (aParam2)

    {

    case AAOPER_DOC_UPDATE_LINK_DATA:

    {

    LONG lEnvCount = aaApi_SelectEnvByTableId(pParam->lTableId);

    if (lEnvCount == 1L)

    {

    CString sAttrRecId = L"";

    sAttrRecId.Format(L"%ld",pParam->lAttributeRecordId);

    LONG lDocLinkCount = aaApi_SelectLinksByAttr(

    pParam->lTableId,

    aaApi_GetEnvTableIdColumnId(pParam->lTableId),

    sAttrRecId);

    if (lDocLinkCount == 1)

    {

    LONG lProjectId = aaApi_GetLinkNumericProperty(LINK_PROP_PROJECTID,0L);

    LONG lDocumentId = aaApi_GetLinkNumericProperty(LINK_PROP_ITEMID,0);

    // Now that you have identified your document, populate the static document buffer.

    LONG lDocCount = aaApi_SelectDocument(lProjectId,lDocumentId);

    // Do whatever you need here.

    }

    }

    }

    }

    return AAHOOK_SUCCESS;

    }