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>
Solved! Go to Solution.
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.
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.
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>
This CS article may help, but it looks like you followed it:
This example throws an error. To refer to an attribute, do I need to specify only its name or add wt.pdmlink.PDMLinkProduct?
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
Note: I included a "-" between the prefix and the auto generated number.
Seems to work.
David
@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?
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;
}
}