Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
239 views
in Technique[技术] by (71.8m points)

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

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...