AS.FORMS.bus.on(AS.FORMS.EVENT_TYPE.formShow, (event, model, view) => {
    const openAttachments = async documentID => {
        let attachments = await AS.FORMS.ApiUtils.simpleAsyncGet(`rest/api/docflow/doc/attachments?documentID=${documentID}`);

        if(attachments.work_files.length){
            $(`table[document_id="${documentID}"]`)
                .closest('.window-body')
                .find('img[src*="images/close.png"]')
                .closest('table')
                .get(0)
                .click();

            window.location.href = '#' + jQuery.param({
                submodule: 'common',
                action: 'open_document',
                document_identifier: documentID,
                file_identifier: attachments.work_files[0].uuid
            });
        }
    }

    let documentID = AS.getUrlParam('document_identifier');

    if(!documentID){
        model.on(AS.FORMS.EVENT_TYPE.dataLoad, async () => {
            const documentID = await AS.FORMS.ApiUtils.getDocumentIdentifier(model.asfDataId);
            openAttachments(documentID);
        });
    }else{
        openAttachments(documentID);
    }
});