Primavera API创建udfcode本地模式



是否知道有人可以在哪里找到通过API添加primavera UDF的示例?我的代码在下面,但运行它时不会发生任何事情。我可以连接到数据库,读取UDF,删除UDF,但不能创建

谢谢

package apitest;
  import com.primavera.bo.base.u;
  import com.primavera.common.value.ObjectId;
  import com.primavera.integration.client.*;
  import com.primavera.integration.client.Session;
  import com.primavera.integration.client.EnterpriseLoadManager;
  import com.primavera.integration.client.RMIURL;
  import com.primavera.integration.common.DatabaseInstance;
  import com.primavera.integration.client.bo.BOIterator;
  import com.primavera.integration.client.bo.object.Project;
  import com.primavera.integration.client.bo.object.UDFCode;
  import com.primavera.integration.client.bo.InternalBOHelper;
  import com.primavera.integration.client.bo.helper.UDFCodeHelper;
  public class API
  {
 public static void main( String[] args )
{
    System.setProperty("primavera.bootstrap.home","C:\P6IntegrationAPI_1");
    Session session = null;
    try
    {
        DatabaseInstance[] dbInstances = Session.getDatabaseInstances(
            RMIURL.getRmiUrl( RMIURL.LOCAL_SERVICE ) );
        // Assume only one database instance for now, and hardcode the username and
        // password for this sample code
        session = Session.login( RMIURL.getRmiUrl( RMIURL.LOCAL_SERVICE ),
            dbInstances[0].getDatabaseId(), "admin", "admin" );

        //u.delete(session, (UDFCode)(new String ("High")));
        UDFCode u = new UDFCode(session);
        u.setCodeValue("cdc");
        u.setDescription("cdcds");    
        u.setObjectId(ObjectId.USESSION_OVERRIDE_ID);
        u.setCodeTypeObjectId(ObjectId.USESSION_OVERRIDE_ID);
        u.setSequenceNumber(0);
        u.create();            

        System.out.println("cdcx");

    }
    catch ( Exception e )
    {
        System.out.println(e.getCause());
    }
    finally
    {
        if ( session != null )
            session.logout();
    }
}

}

P6中的UDF字段实际上是3种类型的表/类。

  1. UdfType-是UDF的类型(名称、数据类型等)
  2. UdfValue-我想这是你想要设置的实际值
  3. UdfCodes-这是用户定义的代码,所以它有点复杂,实际上是一个代码,没有字段

所以,如果你想要一个简单的UDF,只需创建一个UdfType,它是全局数据的一部分,在你添加值之前必须存在。您也可以通过客户端/web添加它,稍后用值填充它。

接下来尝试在Activities上插入一些UdfValues。我每次都是这样;)

使用以下模板代码连接到DB。在使用之前,请确保更改引导程序、用户名和密码值。

import java.util.Date;
import java.util.Iterator;
import com.primavera.PrimaveraException;
import com.primavera.ServerException;
import com.primavera.bo.events.enm.SpreadPeriodType;
import com.primavera.common.value.Duration;
import com.primavera.common.value.ObjectId;
import com.primavera.common.value.spread.ActivitySpread;
import com.primavera.common.value.spread.ActivitySpreadPeriod;
import com.primavera.integration.client.GlobalObjectManager;
import com.primavera.integration.client.Session;
import com.primavera.integration.client.bo.BOIterator;
import com.primavera.integration.client.bo.BusinessObjectException;
import com.primavera.integration.client.bo.enm.ActivityStatus;
import com.primavera.integration.client.bo.enm.ProjectStatus;
import com.primavera.integration.client.bo.object.Activity;
import com.primavera.integration.client.bo.object.ActivityNote;
import com.primavera.integration.client.bo.object.EPS;
import com.primavera.integration.client.bo.object.NotebookTopic;
import com.primavera.integration.client.bo.object.Project;
import com.primavera.integration.client.bo.object.BaselineProject;
import com.primavera.integration.common.CopyActivityOptions;
import com.primavera.integration.common.CopyProjectOptions;
import com.primavera.integration.common.CopyWBSOptions;
import com.primavera.integration.common.DatabaseInstance;
import com.primavera.integration.client.bo.object.*;
import com.primavera.integration.client.*;
import com.primavera.integration.network.NetworkException;
import com.primavera.integration.*;

public class EPSFilter {
    static Session session = null;
    //static Session session = null;
     private static final String PRIMAVERA_BOOTSTRAP_HOME = "primavera.bootstrap.home";
    static final String PRIMAVERA_BOOTSTRAP_HOME_VALUE = "C:\P6EPPM_832\p6";
    static final String PRIMAVERA_USERNAME = "admin";
    static final String PRIMAVERA_PASSWORD = "admin";
    static final String PRIMAVERA_SYSTEM = "pmdb832_n1";
    static void openSession() throws PrimaveraException {
        for (DatabaseInstance dbi : Session.getDatabaseInstances(null)) {
          if (PRIMAVERA_SYSTEM.equalsIgnoreCase(dbi.getDatabaseName())) {
            session = Session.login(null, dbi.getDatabaseId(), PRIMAVERA_USERNAME, PRIMAVERA_PASSWORD);
            //session = Session.login (RMIURL.getRmiUrl( RMIURL.LOCAL_SERVICE ), "1", "admin", "admin");
            System.out.println("Connected to Primavera instance " + PRIMAVERA_SYSTEM);
            return;
          }
        }
        throw new RuntimeException("Error, Primavera instance " + PRIMAVERA_SYSTEM + " not found");
      }

    public static void main(String[] args) throws BusinessObjectException, ServerException, NetworkException {
         try {
             System.setProperty(PRIMAVERA_BOOTSTRAP_HOME, PRIMAVERA_BOOTSTRAP_HOME_VALUE);
            openSession();
        } catch (PrimaveraException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }

您的代码应该按照创建UDF。如果你仍然面临问题。请发布您获得的错误

相关内容

  • 没有找到相关文章

最新更新