Alfresco: How can I check if a value already exists in DB save new values?

99封情书 提交于 2019-12-14 03:32:59

问题


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:


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.



来源:https://stackoverflow.com/questions/40129638/alfresco-how-can-i-check-if-a-value-already-exists-in-db-save-new-values

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!