cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Auto Generated Project Number

SOLVED
Highlighted
Participant

Auto Generated Project Number

Hello All,

Is it possible to auto generate project number. Like WTDocument has OOTB sequence to auto generate it's number.

It is not possible through OIR as OIR is not applicable for Project2.

Message was edited by: kaushik das

1 ACCEPTED SOLUTION

Accepted Solutions

Re: Auto Generated Project Number

Hi Ben,

  • Create two classes. ShowProjectSequence and CustomPROPLFormProcessor.

package ext.datautility;

import wt.fc.PersistenceHelper;

import wt.pds.StatementSpec;

import wt.pom.POMInitException;

import wt.pom.PersistenceException;

import wt.pom.PersistentObjectManager;

import wt.preference.PreferenceHelper;

import wt.projmgmt.admin.Project2;

import wt.query.QueryException;

import wt.query.QuerySpec;

import wt.session.SessionServerHelper;

import wt.util.WTException;

import wt.util.version.WindchillVersion;

import com.ptc.core.components.descriptor.ModelContext;

import com.ptc.core.components.factory.dataUtilities.DefaultDataUtility;

import com.ptc.core.ui.resources.ComponentMode;

import com.ptc.windchill.instassm.ReleaseIdException;

public class ShowProjectSequence extends DefaultDataUtility {

/**

* Overridden method of {@link DefaultDataUtility}.

*

* @param componentId

* the Component ID.

*

* @param datum

* the object upon which this data utility will worked.

*

* @param modelContext

* the object of {@link ModelContext}.

*

* @exception WTException

* throws {@link WTException}/

*

* @return returns the object.

*/

@Override

public Object getDataValue(String componentId, Object datum,

ModelContext modelContext) throws WTException {

System.out.println("Inside data utility");

/*

* Calling the super class method.

*/

final Object obj = super.getDataValue(componentId, datum, modelContext);

/*

* The data utility only works for ComponentMode create.

*/

if (modelContext.getDescriptorMode().equals(ComponentMode.CREATE)) {

System.out.println("Returning the current sequence.");

/*

* Returning the current sequence.

*/

final String seq = getCurrentSequence();

System.out.println("Sequence Value " + seq);

return seq;

}

/*

* Returning the Object.

*/

return obj;

}

private String getCurrentSequence() throws POMInitException, ReleaseIdException, PersistenceException {

return getCurrentSequenceForTenOne();

}

private String getCurrentSequenceForTenOne() {

final boolean isCreateAccess = SessionServerHelper.manager

.isAccessEnforced();

try{

SessionServerHelper.manager.setAccessEnforced(false);

return String.format("%08d", PersistenceHelper.manager

.find((StatementSpec) new QuerySpec(Project2.class)).size());

} catch (QueryException e) {

// TODO Auto-generated catch block

e.printStackTrace();

} catch (WTException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

finally

{

SessionServerHelper.manager.setAccessEnforced(isCreateAccess);

}

return null;

}

}


and

package ext.test.processor;

import java.util.Iterator;

import java.util.List;

import org.apache.log4j.Logger;

import wt.fc.PersistenceHelper;

import wt.log4j.LogR;

import wt.pds.StatementSpec;

import wt.pom.POMInitException;

import wt.pom.PersistenceException;

import wt.projmgmt.admin.Project2;

import wt.query.QueryException;

import wt.query.QuerySpec;

import wt.session.SessionServerHelper;

import wt.util.WTException;

import com.ptc.core.components.beans.ObjectBean;

import com.ptc.core.components.forms.FormResult;

import com.ptc.netmarkets.project.processor.CreatePROPLProjectFormProcessor;

import com.ptc.netmarkets.util.beans.NmCommandBean;

import com.ptc.windchill.instassm.ReleaseIdException;

//ext.test.processor.CustomPROPLFormProcessor

/**

* Custom Processor for create Project.

*

* @author 'true' 12805 -

*

* @version 'true' 1.0

*/

public class CustomPROPLFormProcessor extends

CreatePROPLProjectFormProcessor {

/**

* Private variable for Logger.

*/

private static final Logger LOG = LogR

.getLogger(CustomPROPLFormProcessor.class.getName());

/**

* Do operation of {@link CustomPROPLFormProcessor}.

*

* @param arg0

* NmCommandBean

*

* @param paramList

* list of ObjectBean

*

* @throws WTException

* throws {@link WTException}.

*

* @return corresponding {@link FormResult}.

*/

@Override

public FormResult doOperation(NmCommandBean arg0, List<ObjectBean> paramList)

throws WTException {

// FormResult result =

Project2 localProject = null;

ObjectBean objBean = null;

/*

* Fetching the Project2 from List given.

*/

for (Iterator<ObjectBean> localIterator = paramList.iterator(); localIterator

.hasNext()Smiley Wink {

objBean = localIterator.next();

localProject = (Project2) (objBean.getObject());

}

LOG.debug("sub-type checking");

System.out.println("Before Renumbering");

String number = String.valueOf(Integer.parseInt(getCurrentSequence())+1);

/*

* Setting the value of ProjectNumber.

*/

System.out.println(number);

localProject

.setProjectNumber(number);

LOG.debug("After renumbering");

/*

* Storing the object in ObjectBean.

*/

objBean.setObject(localProject);

/*

* Removing all the parameter of the list.

*/

for (int loop = 0; loop < paramList.size(); loop++) {

paramList.remove(loop);

}

/*

* Adding the obejct of Project2 in the List.

*/

paramList.add(objBean);

/*

* List<ObjectBean> listToGive = new ArrayList<ObjectBean>(1);

* listToGive.add(objBean);

*/

/*

* calling the Super class method.

*/

return super.doOperation(arg0, paramList);

}

private String getCurrentSequence() throws POMInitException, ReleaseIdException, PersistenceException {

return getCurrentSequenceForTenOne();

}

private String getCurrentSequenceForTenOne() {

final boolean isCreateAccess = SessionServerHelper.manager

.isAccessEnforced();

try{

SessionServerHelper.manager.setAccessEnforced(false);

/*

* Instead of QuerySpec you can use custom sequence also.

*/

return String.format("%08d", PersistenceHelper.manager

.find((StatementSpec) new QuerySpec(Project2.class)).size());

} catch (QueryException e) {

// TODO Auto-generated catch block

e.printStackTrace();

} catch (WTException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

finally

{

SessionServerHelper.manager.setAccessEnforced(isCreateAccess);

}

return null;

}

}

  • Add Below lines in Site.xconf.

<!-- data utility --><Service context="default" name="com.ptc.core.components.descriptor.DataUtility"

targetFile="codebase/com/ptc/core/components/components.dataUtilities.properties">

<Option cardinality="singleton" order="0" overridable="true"

requestor="java.lang.Object"

selector="projectNumber"

serviceClass="ext.datautility.ShowProjectSequence"/>

</Service>

  • Run xconfmanager -p to propagate.

  • Add below lines in codebase/config/actions/Custom-action.xml

<objecttype class="wt.projmgmt.admin.Project2" name="project" >

<action ajax="row" name="createProplProject" resourceBundle="com.ptc.netmarkets.projmgmt.projmgmtActionsRB" >

<command class="ext.test.processor.CustomPROPLFormProcessor" method="execute" windowType="popup"/>

</action>

</objecttype>


  • Restart the server.

Not sure whether PTC will support this but it's working for me.

Sorry for the long reply there is no option to attach any file.

Thanks And Regards,

Kaushik

View solution in original post

9 REPLIES 9
Highlighted

Re: Auto Generated Project Number

Project numbering sequence is controlled using the following XML file.

Windchill\loadXMLFiles\rules\project_autonumber_rule.xml

Highlighted

Re: Auto Generated Project Number

Thanks Syed for your quick response.

Additionally I have two more question.

If I change that file should I have to load it ?

if yes then how ?

How to configure the Project number attribute so that the number is auto generated ?

By default the number field is an user input(TextBox)

Thanks And Regards,

Kaushik

Highlighted

Re: Auto Generated Project Number

We can Load the file using LoadFromFile.But the second question still remains.

How to configure the attribute Number for Project so that It will take it as auto genarated not the manual input.

Highlighted

Re: Auto Generated Project Number

SInce there is no concrete answer to the question I assume it's not possible OOTB.

Going for the customization.

Thanks all for their valuable inputs.

Highlighted

Re: Auto Generated Project Number

I'm disappointed that using OIRs for projects is not supported. I have a similar request from upper management, although I have not investigated it yet. Now I know it is apparently not doable.

Kaushik, have you tried to create a PTC support ticket regarding this? At least a customization perhaps? Or totally not able to do it?

Highlighted

Re: Auto Generated Project Number

Hi Ben,

Yes it can be done using customization.You have to write custom processor for that.

Actually I was searching for any OOTB way.

Thanks And Regards,

Kaushik

Highlighted

Re: Auto Generated Project Number

Thanks Kaushik. Do you have any documentation, or point me in the right direction? Or should I just open a support ticket.

I was actually going to have a meeting this morning with upper management and tell them it is not possible. But if you have some reference material, at least I can inform them of the work that will be involved in the customization. And then they can make a better informed decsion.

Re: Auto Generated Project Number

Hi Ben,

  • Create two classes. ShowProjectSequence and CustomPROPLFormProcessor.

package ext.datautility;

import wt.fc.PersistenceHelper;

import wt.pds.StatementSpec;

import wt.pom.POMInitException;

import wt.pom.PersistenceException;

import wt.pom.PersistentObjectManager;

import wt.preference.PreferenceHelper;

import wt.projmgmt.admin.Project2;

import wt.query.QueryException;

import wt.query.QuerySpec;

import wt.session.SessionServerHelper;

import wt.util.WTException;

import wt.util.version.WindchillVersion;

import com.ptc.core.components.descriptor.ModelContext;

import com.ptc.core.components.factory.dataUtilities.DefaultDataUtility;

import com.ptc.core.ui.resources.ComponentMode;

import com.ptc.windchill.instassm.ReleaseIdException;

public class ShowProjectSequence extends DefaultDataUtility {

/**

* Overridden method of {@link DefaultDataUtility}.

*

* @param componentId

* the Component ID.

*

* @param datum

* the object upon which this data utility will worked.

*

* @param modelContext

* the object of {@link ModelContext}.

*

* @exception WTException

* throws {@link WTException}/

*

* @return returns the object.

*/

@Override

public Object getDataValue(String componentId, Object datum,

ModelContext modelContext) throws WTException {

System.out.println("Inside data utility");

/*

* Calling the super class method.

*/

final Object obj = super.getDataValue(componentId, datum, modelContext);

/*

* The data utility only works for ComponentMode create.

*/

if (modelContext.getDescriptorMode().equals(ComponentMode.CREATE)) {

System.out.println("Returning the current sequence.");

/*

* Returning the current sequence.

*/

final String seq = getCurrentSequence();

System.out.println("Sequence Value " + seq);

return seq;

}

/*

* Returning the Object.

*/

return obj;

}

private String getCurrentSequence() throws POMInitException, ReleaseIdException, PersistenceException {

return getCurrentSequenceForTenOne();

}

private String getCurrentSequenceForTenOne() {

final boolean isCreateAccess = SessionServerHelper.manager

.isAccessEnforced();

try{

SessionServerHelper.manager.setAccessEnforced(false);

return String.format("%08d", PersistenceHelper.manager

.find((StatementSpec) new QuerySpec(Project2.class)).size());

} catch (QueryException e) {

// TODO Auto-generated catch block

e.printStackTrace();

} catch (WTException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

finally

{

SessionServerHelper.manager.setAccessEnforced(isCreateAccess);

}

return null;

}

}


and

package ext.test.processor;

import java.util.Iterator;

import java.util.List;

import org.apache.log4j.Logger;

import wt.fc.PersistenceHelper;

import wt.log4j.LogR;

import wt.pds.StatementSpec;

import wt.pom.POMInitException;

import wt.pom.PersistenceException;

import wt.projmgmt.admin.Project2;

import wt.query.QueryException;

import wt.query.QuerySpec;

import wt.session.SessionServerHelper;

import wt.util.WTException;

import com.ptc.core.components.beans.ObjectBean;

import com.ptc.core.components.forms.FormResult;

import com.ptc.netmarkets.project.processor.CreatePROPLProjectFormProcessor;

import com.ptc.netmarkets.util.beans.NmCommandBean;

import com.ptc.windchill.instassm.ReleaseIdException;

//ext.test.processor.CustomPROPLFormProcessor

/**

* Custom Processor for create Project.

*

* @author 'true' 12805 -

*

* @version 'true' 1.0

*/

public class CustomPROPLFormProcessor extends

CreatePROPLProjectFormProcessor {

/**

* Private variable for Logger.

*/

private static final Logger LOG = LogR

.getLogger(CustomPROPLFormProcessor.class.getName());

/**

* Do operation of {@link CustomPROPLFormProcessor}.

*

* @param arg0

* NmCommandBean

*

* @param paramList

* list of ObjectBean

*

* @throws WTException

* throws {@link WTException}.

*

* @return corresponding {@link FormResult}.

*/

@Override

public FormResult doOperation(NmCommandBean arg0, List<ObjectBean> paramList)

throws WTException {

// FormResult result =

Project2 localProject = null;

ObjectBean objBean = null;

/*

* Fetching the Project2 from List given.

*/

for (Iterator<ObjectBean> localIterator = paramList.iterator(); localIterator

.hasNext()Smiley Wink {

objBean = localIterator.next();

localProject = (Project2) (objBean.getObject());

}

LOG.debug("sub-type checking");

System.out.println("Before Renumbering");

String number = String.valueOf(Integer.parseInt(getCurrentSequence())+1);

/*

* Setting the value of ProjectNumber.

*/

System.out.println(number);

localProject

.setProjectNumber(number);

LOG.debug("After renumbering");

/*

* Storing the object in ObjectBean.

*/

objBean.setObject(localProject);

/*

* Removing all the parameter of the list.

*/

for (int loop = 0; loop < paramList.size(); loop++) {

paramList.remove(loop);

}

/*

* Adding the obejct of Project2 in the List.

*/

paramList.add(objBean);

/*

* List<ObjectBean> listToGive = new ArrayList<ObjectBean>(1);

* listToGive.add(objBean);

*/

/*

* calling the Super class method.

*/

return super.doOperation(arg0, paramList);

}

private String getCurrentSequence() throws POMInitException, ReleaseIdException, PersistenceException {

return getCurrentSequenceForTenOne();

}

private String getCurrentSequenceForTenOne() {

final boolean isCreateAccess = SessionServerHelper.manager

.isAccessEnforced();

try{

SessionServerHelper.manager.setAccessEnforced(false);

/*

* Instead of QuerySpec you can use custom sequence also.

*/

return String.format("%08d", PersistenceHelper.manager

.find((StatementSpec) new QuerySpec(Project2.class)).size());

} catch (QueryException e) {

// TODO Auto-generated catch block

e.printStackTrace();

} catch (WTException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

finally

{

SessionServerHelper.manager.setAccessEnforced(isCreateAccess);

}

return null;

}

}

  • Add Below lines in Site.xconf.

<!-- data utility --><Service context="default" name="com.ptc.core.components.descriptor.DataUtility"

targetFile="codebase/com/ptc/core/components/components.dataUtilities.properties">

<Option cardinality="singleton" order="0" overridable="true"

requestor="java.lang.Object"

selector="projectNumber"

serviceClass="ext.datautility.ShowProjectSequence"/>

</Service>

  • Run xconfmanager -p to propagate.

  • Add below lines in codebase/config/actions/Custom-action.xml

<objecttype class="wt.projmgmt.admin.Project2" name="project" >

<action ajax="row" name="createProplProject" resourceBundle="com.ptc.netmarkets.projmgmt.projmgmtActionsRB" >

<command class="ext.test.processor.CustomPROPLFormProcessor" method="execute" windowType="popup"/>

</action>

</objecttype>


  • Restart the server.

Not sure whether PTC will support this but it's working for me.

Sorry for the long reply there is no option to attach any file.

Thanks And Regards,

Kaushik

View solution in original post

Highlighted

Re: Auto Generated Project Number

Hi KD,

Is it possible to do this for Product context as well?

 

Ephraim

Announcements