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 Reply Children
  • 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;

    }