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

Community Tip - Visit the PTCooler (the community lounge) to get to know your fellow community members and check out some of Dale's Friday Humor posts! X

How to get Assigned Item Expression via Workflow?

Anil_SAD
12-Amethyst

How to get Assigned Item Expression via Workflow?

Version: Windchill 11.2

 

Use Case: Just trying to read/modify Assigned Item Expression which is assigned to a WTPART, in the workflow and then i'll just assign expression to wtparts via workflow.


Description:

Hi there,

First of all, I need to explain our daily use of Item Expressions. We usually assign an expression to a WTPART using the Assigned Item Expression. When I do this, we first move the WTPART to the Library where the Option Set is defined. We're using "Assign Advanced Expression" to assign the expression to the WTPART.

What I am trying to do is print the Assigned Item Expression assigned to a WTPART in the workflow and then assign the expression to WTPARTs via the workflow. However, since this “Assigned Expression” attribute is a calculated value, we cannot retrieve it directly. We need to print it by capturing the relationship between the Option Set and Choice with the WTPART.

There is a topic about obtaining Usage Expression in the forum, but with usage expression, this expression can be obtained with respect to the parent WTPART.

https://community.ptc.com/t5/Windchill-Customization/Method-to-get-Assigned-Expression/m-p/923615 

 

Also, I'm using Windchill version 11.2, and I couldn’t find the OptionHelper class in the Javadoc. I guess it's not supported in this version, or maybe I had trouble finding the fully qualified name.

 

ACCEPTED SOLUTION

Accepted Solutions
HelesicPetr
22-Sapphire I
(To:Anil_SAD)

Hi @Anil_SAD 

I don't think so there is easier way. 

PetrH

View solution in original post

8 REPLIES 8
GrahamV
12-Amethyst
(To:Anil_SAD)

Hi, 

 

I posted the question/solution you linked, it just needs a few tweaks to work with WTPart rather than WTPartUsageLink. One question first, do you need the expression in the context of its Assigned Option Set, or just the the full expression? For example, if you've selected COLOUR = "GREEN", "RED", but only green is currently available for selection in the Assigned Option Set, outputting the expression in context of the Assigned Option Set would give COLOUR = "GREEN". The alternative is to output the full expression (COLOUR = "GREEN", "RED"), which is what Windchill shows in the UI.

 

Could you also clarify your requirements too, it's a little unclear what you need the workflow to do, are you saying you need to output the expression from a WTPart to a string, then assign that expression to other WTParts?

 

On the JavaDoc, there are lots of classes that are missing, I honestly don't know why this is, or whether it means they're supported or not, but I think it was in the codebase at 11.2, use with caution though in case it is unsupported.

 

Graham

HelesicPetr
22-Sapphire I
(To:GrahamV)

Hi @GrahamV 

I just add a comment to the JavaDoc. 

This documentation shows only supported methods. If you use method that is not in JavaDoc, there is not guarantee that it will work in the future release. 

PetrH

Anil_SAD
12-Amethyst
(To:GrahamV)

Hi Graham, 

 

Thanks for your reply. 

 

Actually let me explain what'im gonna trying to do specifically, as i mentioned before normally we assign  Item expressions to wtparts manually. But i want to do this semi automatically via Change Notice.

 

For example there will be textbox which includes: part_number1:ItemExpression1, part_number2:ItemExpression2 ... 

Also sure there will be a some kind of dropdown for which defines the context of Option set.

So if i get these inputs from the user then the magic gonna start: i'll have a expression robot for do these things:

 

1)First of all i need to move the wtpart's to Option set's context(this will be a result of user's dropdown input so i'll have a rule for this). 

2) Then i'll assign ItemExpression1 to part_number1 / ItemExpression2 to part_number2

These ItemExpressions can be a bit complex and long like as (COLOUR = "GREEN", "RED" ,"BLUE" AND "WHITE" , "BLACK") etc. 

 

-One question first, do you need the expression in the context of its Assigned Option Set, or just the the full expression?

+ Yea I need full expression (COLOUR = "GREEN", "RED"), which is what Windchill shows in the UI.

 

-What you need the workflow to do, are you saying you need to output the expression from a WTPart to a string, then assign that expression to other WTParts?

Actually first i've thought i need start with READ assigned expression of wtpart, then i'll WRITE/ASSIGN DESIRED expression to DESIRED wtpart.

  

HelesicPetr
22-Sapphire I
(To:Anil_SAD)

Hi @Anil_SAD 

And where is your problem?

The api mentioned in provided link by you works for everything.. 

WTList[] choices = OptionHelper.service.getAllChoices(child, optionSet);

Just replace the Child with your WTPart 

PetrH

Hi @HelesicPetr ,

yea i've converted like the code below and this works fine for the assigned Item expressions which is applied by "Assign Basic Expression". 

But the problem is, normally i'm assigning expressions via "Assign Advanced Expression" ( i think it requires some kind of licence for use this method)

And when i assign expression with this method, WTList returns null with the code below. 

When i assign expressions via basic method: 

SD_11338516_1-1724824410118.png

 

When i used Advanced Expression:

SD_11338516_2-1724824487661.png

 

 

try {
    java.lang.String partNumber = "PARTTEST";
    wt.query.QuerySpec partQuerySpec = new wt.query.QuerySpec(wt.part.WTPart.class);
    partQuerySpec.appendWhere(new wt.query.SearchCondition(wt.part.WTPart.class, wt.part.WTPart.NUMBER, wt.query.SearchCondition.EQUAL, partNumber), new int[]{0});
    wt.fc.QueryResult partResult = wt.fc.PersistenceHelper.manager.find(partQuerySpec);
    if (!partResult.hasMoreElements()) {
        java.lang.System.out.println("Can't find WTPart: " + partNumber);
    } else {
        wt.part.WTPart part = (wt.part.WTPart) partResult.nextElement();
        java.lang.System.out.println("WTPart found: " + part.getNumber());
        wt.fc.QueryResult latestVersions = wt.vc.VersionControlHelper.service.allIterationsOf(part.getMaster());
        if (latestVersions.hasMoreElements()) {
            wt.part.WTPart latestPart = (wt.part.WTPart) latestVersions.nextElement();
            wt.fc.ReferenceFactory referenceFactory = new wt.fc.ReferenceFactory();
            wt.fc.WTReference partRef = referenceFactory.getReference(latestPart);
            com.ptc.windchill.option.model.OptionSet assignedOptionSet = com.ptc.windchill.option.service.OptionHelper.service.getAssignedOptionSet(partRef, null).getOptionSet();
            if (assignedOptionSet != null) {
                java.lang.System.out.println("Option Set: " + assignedOptionSet.getName());
                wt.fc.collections.WTList[] choicesArray = com.ptc.windchill.option.service.OptionHelper.service.getAllChoices(latestPart, assignedOptionSet);
                for (int i = 0; i < choicesArray.length; i++) {
                    wt.fc.collections.WTList choicesList = choicesArray[i];
                    java.lang.System.out.println("Choices Array Index: " + i);
                    if (choicesList == null || choicesList.size() == 0) {
                        java.lang.System.out.println("  WTList is empty or null at index: " + i);
                    } else {
                        for (int j = 0; j < choicesList.size(); j++) {
                            Object obj = choicesList.get(j);
                            if (obj instanceof wt.fc.WTReference) {
                                // Convert WTReference to actual object
                                wt.fc.WTReference wtReference = (wt.fc.WTReference) obj;
                                Object referencedObject = wtReference.getObject();
                                if (referencedObject instanceof com.ptc.windchill.option.model.Choice) {
                                    com.ptc.windchill.option.model.Choice choice = (com.ptc.windchill.option.model.Choice) referencedObject;
                                    java.lang.System.out.println("  Index " + j + ": Choice object, Name: " + choice.getName());
                                } else {
                                    java.lang.System.out.println("  Index " + j + ": Unknown referenced object type: " + referencedObject.getClass().getName());
                                }
                            } else {
                                java.lang.System.out.println("  Index " + j + ": Unknown type, type: " + obj.getClass().getName());
                            }
                        }
                    }
                }
            } else {
                java.lang.System.out.println("Can't find Option Set");
            }
        } else {
            java.lang.System.out.println("No latest version found for WTPart: " + part.getNumber());
        }
    }
} catch (wt.util.WTException e) {
    java.lang.System.out.println("Exception occurred: " + e.getMessage());
}

 

HelesicPetr
22-Sapphire I
(To:Anil_SAD)

Hi @Anil_SAD 

The API does not check licenses, but the advanced expression can be stored in different table so you have to find an another method to get this information. 

PetrH

Yea now i'm able to get full expression with this API 

wt.option.ComplexExpressionData expressionData = com.ptc.windchill.option.expression.ExpressionHelper.getAssignedExpression(
                    (wt.option.Expressionable) latestPart, assignedOptionSet
                );

                if (expressionData != null) {
                   // Get formatted exp
                    java.lang.System.out.println("Formatted Expression: " + expressionData.toString());
                } else {
                    java.lang.System.out.println("No expression found for the given part and option set.");
                }

 Formatted expression just looking like that : returns json string. "The format will be like 1. {"expression":"EXP1","members":[{"expression":"EnUS / Fr","description":" English and French","id":"EXP1"}]} 2. {"expression":"EXP1 || EXP2","members":[{"expression":"\"8-MP\" && \"8GB\"","description":"","id":"EXP1"},{"expression":"\"6-MP\" && \"16GB\"","description":"","id":"EXP2"}]} " so i can parse the expression from this return. 

So reading step is just complated for me now i need to edit this "complexExpressionData" and update it. 

I'll try to use this "assignLocalExpression"

SD_11338516_1-1724837497565.png

 

 

But is there any easy way to do it?

 

HelesicPetr
22-Sapphire I
(To:Anil_SAD)

Hi @Anil_SAD 

I don't think so there is easier way. 

PetrH

Announcements

Top Tags