Alfresco:如何检查DB中是否已经存在一个值以保存新值? [英] Alfresco: How can I check if a value already exists in DB save new values?

查看:118
本文介绍了Alfresco:如何检查DB中是否已经存在一个值以保存新值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Alfresco在工作流程中,一个字段值。我需要检查数据库中是否已经存在值,如果不存在则不保存,请保存。

Alfresco In workflow form one fields values. I need to check values already exist in DB or not if exists don't save if not save different values. Is this possible?

推荐答案

您说的是 DB,但我假设您的意思是存储在Alfresco中的对象的属性资料库。如果是这样,则可以从工作流中嵌入的JavaScript中检查属性值。如果某个属性的名称为 foo:someProperty,则可以使用doc.properties ['foo:someProperty']获取该属性。您可以从工作流程包中获取对象。工作流中的所有文档都位于一个数组中,可以通过bpm_package.children进行访问。

You are saying "DB" but I will assume you mean "properties on an object stored in the Alfresco repository". If so, from JavaScript embedded in your workflow you can check a property value. If a property is named "foo:someProperty" then you can get it using doc.properties['foo:someProperty']. And you can get the object from the workflow package. All of the documents in your workflow are in an array which is accessible with bpm_package.children.

代码如下:

<activiti:taskListener event="complete" class="org.alfresco.repo.workflow.activiti.tasklistener.ScriptTaskListener">
  <activiti:field name="script">
    <activiti:string>
      for (var i = 0; i &lt; bpm_package.children.length; i++)
      {
        var doc = bpm_package.children[i];
        if (doc.properties['foo:someProperty'] === 'some value') {
            doc.properties['foo:someProperty'] = 'some other value';
            doc.save();
        }
      }
    </activiti:string>
  </activiti:field>

有关Alfresco JavaScript API的详细信息,请参见文档

For more info on the Alfresco JavaScript API, see the docs.

如果您的意思不是存储库中的对象,而您确实的确是关系数据库,那么您将必须使用Java实现自定义任务侦听器,然后使用JDBC或其他一些API来查询数据库并更新数据库中的记录。

If you did not mean an object in the repository and you really did mean a relational database, then you'll have to implement a custom task listener using Java, and from there use JDBC or some other API to query your database and update records in the database.

如果这就是您需要做的,那么您可以看看工作流程教程。有一个名为ExternalReviewNotification的类,该类显示如何在Java中实现自定义任务侦听器。您可以实现自己的任务侦听器,以对数据库进行JDBC调用。

If that's what you need to do, then you might take a look at this workflow tutorial. There is a class called ExternalReviewNotification that shows how to implement a custom task listener in Java. You could implement your own task listener that makes the JDBC call to your database.

这篇关于Alfresco:如何检查DB中是否已经存在一个值以保存新值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆