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

We are happy to announce the new Windchill Customization board! Learn more.

Add a Custom Attribute to a specific task in Workflow

rhermann
4-Participant

Add a Custom Attribute to a specific task in Workflow

Is there an easy way to add a custom attribute only to a specific task in a workflow? For example, in the OOTB Change Notice workflow there is an Audit task. How would I add an attribute to this task only?

-Ryan

1 ACCEPTED SOLUTION

Accepted Solutions
kpritchard
4-Participant
(To:rhermann)

ok then change the set statement to

obj.set("IFRQ_Number", IFRQ_Number);

View solution in original post

13 REPLIES 13

You can create variable in Task:

1.jpg

rhermann
4-Participant
(To:vostapenko)

Awesome. I actually got this far on my own. Next I want to take that variable information and map it back into an attribute on the change notice that way it is visible on the details of the change.

Any idea what the code for this is?

kpritchard
4-Participant
(To:rhermann)

It ends on what version you're on... LWCNormalizedObject is the API to use for earlier versions, for 10.2 and beyond use PersistableAdapter. See the JavaDoc for your version for code samples

rhermann
4-Participant
(To:kpritchard)

I'm on Windchill PDMLink 10.2 M020. I downloaded the "JavaDoc" but it is way over my head. Any Chance you could supply me with the code snippet I need to put in the expression robot? The internal name of the attribute I am working with is "IFRQ_Number" and the variable is named the same. I tried this code but there is an error when I do check syntax... not sure how to fix or if this is even the correct code:

wt.change2.WTChangeOrder2thisNotice = (wt.change2.WTChangeOrder2thisNotice) primaryBusinessObject;

com.ptc.core.lwc.server.LWCNormalizedObject obj = new com.ptc.core.lwc.server.LWCNormalizedObject(thisNotice,null,null,null);

obj.load("IFRQ_Number");

Object nameValue = obj.get("IFRQ_Number");

ChangeNoticeName = obj.get("IFRQ_Number")toString();

KD
4-Participant
4-Participant
(To:rhermann)

Hi,

Try below code.

wt.change2.WTChangeOrder2 thisNotice = (wt.change2.WTChangeOrder2) primaryBusinessObject;

com.ptc.core.lwc.server.PersistableAdapter obj = new com.ptc.core.lwc.server.PersistableAdapter(thisNotice,null,null,null);

obj.load("IFRQ_Number");

String IFRQ_Number= (String) obj.get("IFRQ_Number");

Thanks,

Kaushik

rhermann
4-Participant
(To:KD)

Hi,

Thanks for the help. I dropped that code in my expression robot and hit check syntax and got the following (see image) im not sure how to fix it:

Remy Variable to Attribute Mapping_1.PNG

kpritchard
4-Participant
(To:rhermann)

is IFRQ_Number already defined as a workflow process variable? If so drop the String declaration in your code snippet.

If you want to set the value back to the Change Task you need to have an attribute for it. You would use the sequence of:

obj.load("IFRQ_Number"); // assumes that this is what the attribute is called in your Change Object

obj.set("IFRQ_Number", myProcessVariable); //assumes that myProcessVariable is defined in your workflow and is the same data type as IFRQ_Number

obj.apply();

// then you need to update the Change Object

wt.fc.PersistenceHelper.manager.modify(thisNotice);

rhermann
4-Participant
(To:kpritchard)

Hi Kier,

Both my Variable and the attribute on the Change notice are called "IFRQ_Number" and both are of type string.

I tried some of the updates and am still getting a syntax error (see image):

Remy+Variable+to+Attribute+Mapping_2.PNG

kpritchard
4-Participant
(To:rhermann)

ok then change the set statement to

obj.set("IFRQ_Number", IFRQ_Number);

rhermann
4-Participant
(To:kpritchard)

Thanks Kier! I updated the code per your note and it works great. Just an FYI for anyone that might read this post, make sure the expression robot is placed after the task in the workflow where the variable is being set.

Here is the code that I used that works (specific to my use case of an atribute and variable both of type string with the internal name of "IFRQ_Number"):

wt.change2.WTChangeOrder2 thisNotice = (wt.change2.WTChangeOrder2) primaryBusinessObject;

com.ptc.core.lwc.server.PersistableAdapter obj = new com.ptc.core.lwc.server.PersistableAdapter(thisNotice,null,null,null);

obj.load("IFRQ_Number");

obj.set("IFRQ_Number", IFRQ_Number);

obj.apply();

wt.fc.PersistenceHelper.manager.modify(thisNotice);

Can you post a picture of this section of workflow, I am kind of confused on how I should set mine up so that the activity will display the desired attributres.

rhermann
4-Participant
(To:zsmith)

Theres not much to screenshot... it is literally a single task (with the variable set up inside it) followed directly by an expression robot with the above code placed in it.

By setting the variable in the task via the workflow administration utility, it makes the field visable and editable to the user when they recieve their task. They enter in a value and complete their task. The flow then goes from the task to the aforementioned expression robot. The robot grabs the value that the user entered and stores it in the attribute so that the value now shows up on the details page of the change object.

kpritchard
4-Participant
(To:zsmith)

Zane, to add to what Ryan has provided above...

You'll have a process variable as well as a task variable. When you create the task variable you can configure to initialize from and copy into the process variable. This allows a value to be passed from one workflow node to another.

Ryan - I like using separate Expression Robots (as you have done) so I don't lose track of code. The code could also be placed in a Task Transition such as Complete.

Top Tags