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

Community Tip - Have a PTC product question you need answered fast? Chances are someone has asked it before. Learn about the community search. X

How add a prefix to an autogenerated number?

VladiSlav
17-Peridot

How add a prefix to an autogenerated number?

Hello everyone, can you please tell me how can I add a prefix from business attr to an autogenerated number?
How to get this number: ABC.0000185268?

 

<AttributeValues objType="wt.part.WTPart">
	<AttrConstraint id="number" algorithm="com.ptc.core.rule.server.impl.GatherAttributeConstraints">  	         
		<Value algorithm="com.ptc.core.rule.server.impl.GetServerAssignedConstraint"/>      
	</AttrConstraint>        
</AttributeValues>

 

VladiSlav_0-1640693933339.png

 

ACCEPTED SOLUTION

Accepted Solutions
BenLoosli
23-Emerald II
(To:VladiSlav)

Wrong part of the OIR to modify.

Look for:

<!-- set the number to a generated number -->
<AttrValue id="number" algorithm="com.ptc.windchill.enterprise.revisionControlled.server.impl.NumberGenerator">
<Arg>
ABC.
</Arg>
<Arg>
{GEN:wt.enterprise.SequenceGenerator:WTPARTID_seq:10:0}
</Arg>
</AttrValue>

 

You can put anything you like in the first ARG statement for your prefix and then let the system generate the 10 character number to follow.

View solution in original post

12 REPLIES 12
BenLoosli
23-Emerald II
(To:VladiSlav)

Wrong part of the OIR to modify.

Look for:

<!-- set the number to a generated number -->
<AttrValue id="number" algorithm="com.ptc.windchill.enterprise.revisionControlled.server.impl.NumberGenerator">
<Arg>
ABC.
</Arg>
<Arg>
{GEN:wt.enterprise.SequenceGenerator:WTPARTID_seq:10:0}
</Arg>
</AttrValue>

 

You can put anything you like in the first ARG statement for your prefix and then let the system generate the 10 character number to follow.

, thanks for your reply. It turned out to add constant values. But it does not work, it turns out to add a value from a global attribute (soft attribute or IBA).

Please tell me how this can be done?

I tried different ways, but with no result. Here is an example of the final attempt

 

 

<!-- set the number to a generated number -->
<AttrValue id="number" algorithm="com.ptc.windchill.enterprise.revisionControlled.server.impl.NumberGenerator"> 
  <!-- add a V prefix for variant parts -->
  <Value algorithm="wt.rule.algorithm.BooleanBranch">
	 <Value algorithm="wt.rule.algorithm.EqualsTest">
		<Attr id="genericType"/>
		<Arg>variant</Arg>	
	 </Value>
	 <Arg>V</Arg>
	 <Arg></Arg>
  </Value>
  <!-- the sequence -->
  <Arg id="IBA|wt.pdmlink.PDMLinkProduct.ИНДЕКС_ТС"/>
  <Arg>{GEN:wt.enterprise.SequenceGenerator:WTPARTID_seq:10:0}</Arg>
</AttrValue>

 

 

BenLoosli
23-Emerald II
(To:VladiSlav)

This example throws an error. To refer to an attribute, do I need to specify only its name or add wt.pdmlink.PDMLinkProduct?

 

VladiSlav_0-1640709595403.png

 

VladiSlav_1-1640709679472.png

 

 

BenLoosli
23-Emerald II
(To:VladiSlav)

Take out the section of code between <Value> and </Value> as it is not needed in what you are doing.

 

<!-- set the number to a generated number -->
<AttrValue id="number" algorithm="com.ptc.windchill.enterprise.revisionControlled.server.impl.NumberGenerator">
<Arg>
id=IBA|<paste your IBA internal name here>
</Arg>
<Arg>
{GEN:wt.enterprise.SequenceGenerator:WTPARTID_seq:10:0}
</Arg>
</AttrValue>

 

 Your example is missing the </Arg> after your id-IBA| statement.

thank you, your solution works if the required attribute is present in Part.
The attribute we need is in the context of "Product".

To use your solution, I added an alias with the name "test" to the Part attribute.
For the "test" attribute in the "Mapping" field, I specified "containerReference^wt.pdmlink.PDMLinkProduct~ИНДЕКС_ТС"

Please tell me what to change the "IBA" to refer to the alias attribute?

This is doable.

I create the Product attribute Index TS and gave it a value of ABCD.

The OIR uses my custom algorithm to get the value of Index TS from the Product the Part is being created in.

 

During creation the I logged the running of the algorithm and the value of Index TS.

2021-12-29 10:23:26,887 INFO [ajp-nio-127.0.0.1-8010-exec-4] wt.system.out admin - **** Running algorithm ext.customRuleAlgorithm.GetContextAttributeValue
2021-12-29 10:23:26,891 INFO [ajp-nio-127.0.0.1-8010-exec-4] wt.system.out admin - **** INDEX_TS = ABCD

 

d_graham_0-1640791828380.png

 

Note: I included a "-" between the prefix and the auto generated number.

d_graham_1-1640792082458.png

 

Seems to work.

 

David

d_graham, can you share more detailed information, otherwise I still didn't understand how you implemented it?

@VladiSlav
I used the OOTB number generator and my custom code the get the attribute value.

So, create a variable holds the value of Index_TS.

set number to the variable’s value, a “-“ and the OOTB generated number.

Like most programming, divide and conquer 👍

 

I did have to write the code to get the value of Index_TS from the Product as there’s no OOTB way to do what you require. But that’s par for the course. We can’t expect any application to do everything we want OOTB.

 

Is that clear now?

d_graham, please share your custom algorithm

,
d_graham thank you very much for your help.
 
 This article also helped me (If it is allowed to specify links to third-party sources here). If someone encounters this problem, then I post the final code:
import wt.enterprise.EnterpriseHelper;
import wt.iba.value.DefaultAttributeContainer;
import wt.iba.value.IBAHolder;
import wt.iba.value.IBAValueUtility;
import wt.iba.value.litevalue.AbstractValueView;
import wt.iba.value.service.IBAValueHelper;
import wt.inf.container.WTContainerRef;
import wt.rule.algorithm.RuleAlgorithm;
import wt.util.WTContext;
import wt.util.WTException;

import java.rmi.RemoteException;
import java.util.Locale;

public class CustomNumberRule implements RuleAlgorithm {
    @Override
    public Object calculate(Object[] args, WTContainerRef wt_container_ref) {
        String iba_name = "ИНДЕКС_ТС";
        String iba_value = "";
        String num = "ОШИБКА ГЕНЕРАЦИИ";
        try {
            num = EnterpriseHelper.getNumber(args);
            String name;

            IBAHolder obj_iba_holder = (IBAHolder) wt_container_ref.getObject();
            IBAHolder iba_holder = IBAValueHelper.service.refreshAttributeContainer(obj_iba_holder, null, WTContext.getContext().getLocale(), null);
            DefaultAttributeContainer default_attribute_container = (DefaultAttributeContainer) iba_holder.getAttributeContainer();

            for (AbstractValueView abstract_value_view : default_attribute_container.getAttributeValues()) {
                name = abstract_value_view.getDefinition().getName();
                if (iba_name.equalsIgnoreCase(name)) {
                    iba_value = IBAValueUtility.getLocalizedIBAValueDisplayString(abstract_value_view, Locale.getDefault());
                    break;
                }
            }
        } catch (RemoteException | WTException e) {
            e.printStackTrace();
        }

        return iba_value + "." + num;
    }
}​
Announcements
Top Tags