【问题标题】:Is there any way to create multiple records at once in BMC Remedy using Java?有没有办法使用 Java 在 BMC Remedy 中一次创建多个记录?
【发布时间】:2020-02-06 08:00:37
【问题描述】:

一次获取 ARServerUser 上下文并在循环中多次调用 setEntry 方法是否很好,或者有更好的方法吗?

【问题讨论】:

    标签: java remedy bmc itsm


    【解决方案1】:

    API 提供了这一点。查看ARServerUserjavadoc:

    它是这样使用的:

    //connect to AR server
    ARServerUser server = new ARServerUser();
    server.setServer("localhost");
    server.setUser("Demo");
    server.setPassword("");
    // begin bulk transaction
    server.beginBulkEntryTransaction();
    //create and submit Entry Objects
    
    for(int x = 0; x < 10; x++){
      try {
            Entry entry = new Entry();
            entry.put(Constants.AR_CORE_SUBMITTER, new Value(submitter));
            entry.put(Constants.AR_CORE_STATUS,new Value(status, DataType.ENUM));
            entry.put(Constants.AR_CORE_SHORT_DESCRIPTION, new Value(shortDesc));
            entryIdOut = server.createEntry(formName, entry);
        } catch (ARException e) {
            ARExceptionHandler(e, "Cannot create the entry." );
        }
    }
    //Commit Bulk transaction: all entries are saved to Remedy
     List<BulkEntryReturn>  bulkIds = server.endBulkEntryTransaction(Constants.AR_BULK_ENTRY_ACTION_SEND);
     //bulkIds now contains all the entry Ids for your committed entries
    

    请注意,上面的代码有一些未初始化的变量,因此不会按原样运行(并且可能会抛出ARBulkException

    【讨论】:

    • 请让我知道最后一行 server.endBulkEntryTransaction(Constants.AR_BULK_ENTRY_ACTION_SEND) 正在做什么以及此方法中参数的含义。
    • 这基本上是提交。如果您不调用server.beginBulkEntryTransaction();,则每次调用server.createEntry(formName, entry); 都会提交条目,程序将等待结果。 server.endBulkEntryTransaction() 与 SQL 中的“commit”相同
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-11-05
    相关资源
    最近更新 更多