how to get a filename attached to a record in AX 2012.?

how to get a filename attached to a record in AX 2012… e.g., I have some table named table1 in which I have attached a file with each record.

Now, i want to write a job to fetch the name of files attached to a particular record in a table.

I got it working as:

static void CheckAttacheddocu(Args _args)

{

Attachmenttable objAttachment;

DocuRef obj_docuRef;

;

select objAttachment

where objAttachment.AttachmentId == “001”;

select obj_docuRef

where obj_docuRef.RefRecId == objDev_Attachment.RecId;

info(obj_docuRef.Name);

}