阅读和查看 Automation Anywhere 文档

Automation 360

关闭内容

内容

打开内容

在自定义包中为循环操作添加迭代器

  • 已更新:2020/04/03

    在自定义包中为循环操作添加迭代器

    在包中为 Loop action 添加一个迭代器。

    将迭代器添加到循环操作

    • 要创建迭代器,请将 BotCommand 注释的 commandType 属性的值设置为Iterator
    • 迭代器需要两种方法,分别由 HasNextNext 注释定义。
    @BotCommand(commandType = BotCommand.CommandType.Iterator)
    @CommandPkg(name = "loop.iterators.files",
            label = "For each file in folder",
            node_label = "for each file and assign file name and extension to {{returnTo}}",
            description = "Iterator for each file in folder.",
            return_type = DataType.DICTIONARY,
            return_sub_type = DataType.STRING,
            return_required = true,
            return_description = "Note: Access the 'name' key to access file name and 'extension' 
            key to access the file extension.",
            return_label = "Assign file name and extension to this variable")
    public class FileLoop extends AbstractCommandFileIterator {
     
        @Idx(index = "1", type = AttributeType.TEXT)
        @Pkg(label = "Folder path")
        @Inject
        @NotEmpty
        private String folderPath;
     
        @HasNext
        public boolean hasNext() {
            return getFileIterator(folderPath).hasNext();
        }
     
        @Next
        public Value<?> next() {
            Map<String, Value> returnValueMap = new HashMap<>();
     
            FileIterator fileIterator = getFileIterator(folderPath);
            String fileName = fileIterator.getNext();
     
            returnValueMap.put(FILE_NAME, new StringValue(fileIterator.getFileName(fileName)));
            returnValueMap.put(EXTENSION, new StringValue(fileIterator.getExtension(fileName)));
     
            return new DictionaryValue(returnValueMap);
     
        }
     
        public void setFolderPath(String folderPath) {
            this.folderPath = folderPath;
        }
    }
    发送反馈