Alfresco: How can I check if a value already exist

2019-09-20 19:17发布

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?

1条回答
Luminary・发光体
2楼-- · 2019-09-20 20:02

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.

The code would look something like:

<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>

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

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.

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.

查看更多
登录 后发表回答