/******************************************************
@Author : Karthikeyan A
@Created: 23-Jun-2010, Qatar
@Purpose : To delete a specific attachment from a document, provided the attachment
@Author : Karthikeyan A
@Created: 23-Jun-2010, Qatar
@Purpose : To delete a specific attachment from a document, provided the attachment
name and the doc url are provided@Type : Function
@Name : removeAttachment
@Param : targDB:NotesDatabase, The database in which the attachment is present
@Name : removeAttachment
@Param : targDB:NotesDatabase, The database in which the attachment is present
@Param : doc_Url:String, The url of the document that contains the attachment
@Param : fileName:String, The name of the attachment to be deleted
*******************************************************/
*******************************************************/
function removeAttachment(targDB,doc_Url,fileName) {
//passing parameters by referencevar docUrl:String= doc_Url;
var targetDB:NotesDatabase=targDB;
var attachmentName:String =fileName;
//deducing the document's unid from the document's url
docUrl=@Left(docUrl,"?");
var docUnid=@RightBack(docUrl,"/");
//setting the handle to the document
var docContext:NotesDocument=targetDB.getDocumentByUNID(docUnid);
if (docContext==null) {
viewScope.CodeError="Either the UNID is invalid or the target db does not contain the doc or both";
return;
}
//getting the handle to the concerned attachment
var embObj:NotesEmbeddedObject=docContext.getAttachment(attachmentName);
if (embObj==null) {
viewScope.CodeError="No attachment is found by the name "+ attachmentName;
return;
}
//remove the attachment
embObj.remove()
//save the document so that the changes gets into effect.. other wise no change will be infered
docContext.save(true,false);
}
Hope this helps :)
No comments:
Post a Comment