Automation Anywhere

Automation Anywhere Automation 360

關閉內容

內容

開啟內容

處理自訂套件中的工作階段

  • 已更新:4/09/2021
    • Automation 360 v.x
    • 建立
    • RPA 工作區

處理自訂套件中的工作階段

您可以使用會話名稱從 SessionMap 提取會話。 在同一軟件包中,您可以使用會話在操作之間傳遞信息,但不能在其他軟件包中傳遞信息。

配置以下屬性

  • 將註釋應用於類字段並添加相應的公共設置器。
  • 使用 sessions 屬性檢索 SessionMap 。
  • 將變量類型設置爲 Map<String, Object>
  • 設置 AttributeType文本會話。如果 type = text,則爲常規會話;如果 type = session,則爲 sharedSession

啓動新會話

@BotCommand
@CommandPkg(label = "Start session", name = "startSession", description = "Start new session", 
icon = "pkg.svg", node_label = "start session {{sessionName}}|") public class Start {
 
    @Sessions
    private Map<String, Object> sessions;
     
    @Execute
    public void start(@Idx(index = "1", type = TEXT) @Pkg(label = "Session name", 
    default_value_type = STRING, default_value = "Default") @NotEmpty String sessionName) {
 
        // Check for existing session
        if (sessions.containsKey(sessionName))
            throw new BotCommandException(MESSAGES.getString("xml.SessionNameInUse", sessionName));
 
        // Do some operation
 
        // Create new session
        sessions.put(sessionName, new Session(operation));
    }
    public void setSessions(Map<String, Object> sessions) {
        this.sessions = sessions;
    }
}

結束會話

@BotCommand
@CommandPkg(label = "End session", name = "endSession", description = "End session", icon = 
"pkg.svg", node_label = "End session {{sessionName}}|")
public class EndSession {
    @Sessions
    private Map<String, Object> sessions;
    @Execute
    public void end(
            @Idx(index = "1", type = TEXT) @Pkg(label = "Session name", default_value_type = STRING, 
            default_value = "Default") @NotEmpty String sessionName) {
                 
        sessions.remove(sessionName);   
    }  
    public void setSessions(Map<String, Object> sessions) {
        this.sessions = sessions;
    }
}

新增工作階段

在下面的示例中,使用字符串對象(儘管在實際操作中,您可以使用複雜對象)。

@BotCommand
@CommandPkg(label = "[[SessionDemo.label]]", description = "[[SessionDemo.description]]", icon = "sample.svg", name = "sessionDemo")
public class SessionDemo {

	// Sessions are provided as a Map. Actions can add or remove entries in this
	// Map.
	// The choice to reuse/overwrite/delete/add any Object in this Map belongs to
	// the actions, and the framework makes no assumption regarding it.
	@Sessions
	private Map<String, Object> sessionMap;

	@Execute
	public void execute(@Idx(index = "1", type = TEXT)
	@Pkg(label = "[[SessionDemo.name.label]]")
	@NotEmpty
	String name) {
		if (!sessionMap.containsKey(name))
			sessionMap.put(name, "Some Value");
	}

	// Ensure that a public setter exists.
	public void setSessionMap(Map<String, Object> sessionMap) {
		this.sessionMap = sessionMap;
	}
}

設置會話變量

以下示例說明如何開發操作(例如 ,設置會話變量)。在操作中,將檢索會話詳細信息並將其存儲爲會話變量,以便可以在特定軟件包中使用該信息。

@BotCommand
@CommandPkg(label = "[[SessionDemo2.label]]", description = "[[SessionDemo2.description]]", icon = "sample.svg", name = "SessionDemo2",
return_type = DataType.STRING)
public class SessionDemo2 {

	// Sessions are provided as a Map. Actions can add or remove entries in this
	// Map.
	// The choice to reuse/overwrite/delete/add any Object in this Map belongs to
	// the actions, and the framework makes no assumption regarding it.
	@Sessions
	private Map<String, Object> sessionMap;

	@Execute
	public Value<?> execute(@Idx(index = "1", type = TEXT)
	@Pkg(label = "[[SessionDemo2.name.label]]")
	@NotEmpty
	String name) {
		if (sessionMap.containsKey(name)) {
			return new StringValue(sessionMap.get(name));
		}	
		return new StringValue("session does not exist");
	}
	// Ensure that a public setter exists.
	public void setSessionMap(Map<String, Object> sessionMap) {
		this.sessionMap = sessionMap;
	}
}
傳送意見反饋