You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Kofax自定义模块开发:数据获取、流程跳转与数据传递问询

Kofax自定义模块KC.CM.Divalto技术问题解决方案

我已创建基础Kofax自定义模块KC.CM.Divalto,目标功能为:读取批次提取的数据、调用WebService、根据WebService响应跳转至验证模块或PDF生成器。当前已实现可正常返回响应的WebService测试调用,现有代码如下:

internal class Program
{
  static void Main(string[] args)
  {
      AppDomain.CurrentDomain.AssemblyResolve += (sender, eventArgs) => KcAssemblyResolver.Resolve(eventArgs);
      Run(args);
      return;
  }

  static void Run(string[] args)
  {
      var login = new Login();
      login.EnableSecurityBoost = true;
      login.Login();
      login.ApplicationName = "KC.CM.Divalto";
      login.Version = "1.0";

      login.ValidateUser("KC.CM.Divalto.exe", false, "", "");

      var session = login.RuntimeSession;

      var activeBatch = session.NextBatchGet(login.ProcessID);

      MessageBox.Show("activeBatch.Name: " + activeBatch.Name);

      activeBatch.BatchClose(
           KfxDbState.KfxDbBatchReady, KfxDbQueue.KfxDbQueueNext, 0, "");

      var url = "http://localhost/webservice.asmx";

      var data1 = "data1";
      var data2 = "data2";
      var data3 = "data3";

      Dictionary<string, string> data = new Dictionary<string, string>();
      data.Add("data1", data1);
      data.Add("data2", data2);
      data.Add("data3", data3);


      WsCaller wsCaller= new WsCaller();
      WsResponse returnValue =
          wsCaller.SoapApiCaller(url, data1, data2, data3);

      Console.WriteLine(returnValue);
      MessageBox.Show("returnValue" + returnValue);

      session.Dispose();
      login.Logout();
  }
}

问题1:如何从KTM Server获取KTM验证模块中显示的提取字段值?

通过KfxDocument和KfxField对象遍历批次中的文档与字段,即可获取KTM提取的字段值:

// 获取批次内的文档集合
var docs = activeBatch.Documents;
foreach (KfxDocument doc in docs)
{
    // 遍历文档下的所有字段
    var fields = doc.Fields;
    foreach (KfxField field in fields)
    {
        // 读取字段名与对应值
        string fieldName = field.Name;
        string fieldValue = field.Value;
        // 可将字段值存入字典供后续使用
        data[fieldName] = fieldValue;
    }
    // 释放文档资源,避免内存泄漏
    doc.Dispose();
}

注意:字段名称需与KTM项目中配置的字段名完全匹配,遍历完成后要及时释放文档对象资源。


问题2:如何根据WebService响应跳过验证模块,当响应为正时直接跳转至PDF生成器?

通过修改BatchClose方法的目标队列参数,控制批次流向:

  • 响应为正时,将批次发送至PDF生成器对应的队列
  • 响应为负时,发送至验证模块队列

示例代码:

WsResponse returnValue = wsCaller.SoapApiCaller(url, data1, data2, data3);

KfxDbQueue targetQueue;
// 根据WebService响应判断目标队列(需根据实际WsResponse结构调整判断逻辑)
if (returnValue.IsSuccess)
{
    // 替换为PDF生成器对应的队列枚举值(需在Kofax控制台确认)
    targetQueue = KfxDbQueue.KfxDbQueueCustom1;
}
else
{
    // 跳转至验证模块队列
    targetQueue = KfxDbQueue.KfxDbQueueValidation;
}

// 关闭批次并指定目标队列
activeBatch.BatchClose(
    KfxDbState.KfxDbBatchReady, 
    targetQueue, 
    0, 
    "根据WebService响应跳转");

注意:需提前在Kofax Capture管理控制台中配置好PDF生成器对应的队列,并确认其枚举值。


问题3:如何将WebService返回值传递至验证模块,例如设置属性存储状态信息或错误信息?

利用批次的自定义属性存储WebService返回值,验证模块可通过批次对象读取这些属性:

设置批次自定义属性

// 将WebService响应状态存入自定义属性
activeBatch.Attributes.SetValue("WsResponseStatus", returnValue.Status.ToString());
// 将错误信息存入自定义属性
activeBatch.Attributes.SetValue("WsErrorMessage", returnValue.ErrorMessage ?? string.Empty);
// 保存属性更改
activeBatch.Attributes.Save();

在验证模块中读取属性

在验证模块的脚本或自定义代码中,通过当前批次对象获取属性:

var currentBatch = RuntimeSession.CurrentBatch;
string wsStatus = currentBatch.Attributes.GetValue("WsResponseStatus");
string wsError = currentBatch.Attributes.GetValue("WsErrorMessage");
// 可将信息显示在验证界面或用于业务逻辑判断

若只需简单存储文本信息,也可使用批次的Comment字段,但自定义属性更适合结构化存储多类信息。


内容的提问来源于stack exchange,提问作者davidvera

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.16 06:05:21