发新话题
打印

[已解决] 关于附件的hook脚本( 此文章被查看:373次,被回复:2篇!! )

本主题由 yunshan 于 2008-4-14 12:39 关闭

关于附件的hook脚本

Dim session
        Dim entity
        Dim attachment

         set session = getsession
    currentid = GetFieldValue("id").GetValue
        set entity = session.GetEntity("Review",currentid)
         
    set attachFields = entity.AttachmentFields
    set oneField = attachFields.Item(0)
   
        set attachs = oneField.Attachments
        numAttachments = attachs.Count

        For x = 0 to numAttachments
            
            set attachment = attachs.Item(x)
               
                msgbox attachment1
                fileName = attachment.FileName
                   Next
老是抱缺少对象  不知道哪个地方写错了


问题已经解决 [打开主题]
本主题的最佳答案为 [ 3 楼].



© 本文为 ljs53SCMLife 共同所有,未经同意,请勿转载 ©如该文侵犯了您的版权,请联系管理员

TOP

有这几个地方需要注意一下:
1. 写CQ内部脚本,最好避免使用entity作为对象名,可能会与系统的冲突。
2. msgbox attachment1,这句应该就是导致出现错误的原因所在,因为attachment1就是不存在的。



© 本文为 yunshanSCMLife 共同所有,未经同意,请勿转载 ©如该文侵犯了您的版权,请联系管理员

TOP

msgbox attachment1
改成msgbox attachment.FileName 试试,其他地方没看出来错误。

我用perl写过类似的,是可以运行的脚本,你可以参考一下:
sub AttachmentSize{

# Get the collection of attachment fields
$attachfields = $entity->GetAttachmentFields();

# Get the first attachment fields
$attachfield1 = $attachfields->Item(0);

# Now get the collection of attachments from the attachments field
$attachments = $attachfield1->GetAttachments();

# Retrieve the number of attachments for the for loop
$numattachments = $attachments->Count();
$result="";

for ($x = 0 ; $x < $numattachments ; $x++)
{
# Retrieve the correct attachment
$attachment = $attachments->Item($x);
# Get the filename and filesize for the attachment and print out
# the results
$filename = $attachment->GetFileName();
$filesize = $attachment->GetFileSize();
$result =$result."Attached file: ".$filename." -size: ".$filesize;

}
  # result =$result."Attached file: ";
  return $result;

[ 本帖最后由 tinali 于 2008-4-14 14:33 编辑 ]


最佳答案
该回答被楼主/管理员列为正解!



© 本文为 tinaliSCMLife 共同所有,未经同意,请勿转载 ©如该文侵犯了您的版权,请联系管理员

TOP

发新话题