Jazz Forum Welcome to the Jazz Community Forum Connect and collaborate with IBM Engineering experts and users

How to get value of Custom Attributes in RTC extensions ? a simple example of text field can help me.

I'm writing RTC extensions for customized email rules. For sending an email to the owner I can't use the Owner built-in field. I need to use my own custom field(This is a requirement). I don't know how to read the custom field. I thought it would be easy like
String assigned_developer = workItem.getAttribute("assigned.developer").getValue();
where assigned.developer is the Id of the custom attribute.

Using the samples from the forum below code snippet I get Null pointer exception: I'm using this in Process advisor Sample code(which is working fine). The exception is in the first for(){}

 IAuditableCommon iac = saveParameter.getSaveOperationParameter().getAuditableCommon();
                    @SuppressWarnings("deprecation")
                    IWorkItemCommon workItemCommon = iac.getPeer(IWorkItemCommon.class);  //shows deprecated
                    //List<IAttributeHandle> wi_attribs = workItem.getCustomAttributes();   
                    for(IAttribute ia:workItemCommon.findAttributes(saveParameter.getOldProcessArea().getProjectArea(), monitor) )  // this is where I get null pointer exception
                    {
                        System.out.println("\n For started 4444444! \n ");
                        if(workItem.hasAttribute(ia))
                        {
                            System.out.println("processing for variable="+ia.getDisplayName()+" attrib type="+ia.getAttributeType());
                            try
                            {
                                System.out.println("\n TRy started here!! \n ");
                        // this will throw exception if not enumeration
                                IEnumeration<ILiteral> enumeration = (IEnumeration<ILiteral>)workItemCommon.resolveEnumeration(ia, monitor);
                                if(enumeration!=null)
                                {
                                    String[] iaval = ia.getValue(iac, workItem, monitor).toString().split(":");
                                    if(iaval.length>1 && iaval[1]!=null)
                                    {                                                       
                                        List<ILiteral> enumerationLiterals = enumeration.getEnumerationLiterals();
                                        for (ILiteral literal : enumerationLiterals)
                                        {
                                            System.out.println("\n Second For here!! \n ");
                                            if(literal.getIdentifier2().getStringIdentifier().equalsIgnoreCase(iaval[1]))
                                            {
                                                System.out.println("attribute name="+ia.getIdentifier() +", type"+"="+ia.getAttributeType()+" literal="+literal.getIdentifier2().getStringIdentifier()+" literal name="+literal.getName());                                       
                                                break;
                                            }
                                        }
                                    }
                                }
                            }
                            catch (Exception e)
                            {
                                System.out.println("\n This is from CATCH started here!! \n ");
                                System.out.println("Exception="+e.toString());
                            }                       
                        }
                    }

Any help would be highly appreciated.

1

0 votes


Accepted answer

Permanent link
Start here https://rsjazz.wordpress.com/2013/01/02/working-with-work-item-attributes/
There are many more examples on that blog, including https://rsjazz.wordpress.com/2015/02/25/a-rtc-workitem-command-line-version-2-1/
There are server examples as well.
anup Gaur selected this answer as the correct answer

0 votes

Comments

Hi Ralph,

Thanks for the pointers. This was really a great help.The code from your workitem commandline example for getting the process area and the team repository handle really helped.
I used the common instead of the Client lib.
@SuppressWarnings("deprecation")
                IWorkItemCommon workItemCommon = iac.getPeer(IWorkItemCommon.class);
                //classification attribute
                IAttribute myattr = workItemCommon.findAttribute(workItem.getProjectArea(), "my.attribute.id", monitor);
Object myattributevalue = workItem.getValue(myattr);

The above code works like a charm for string fields. I now have to extend it for enumerations.
Thanks again.


forgot to mention in the above code snippet
iac is IAuditableCommon

and getPeer() gives me deprecation warnings

Anup, using the common API is a good move. I have to confess, sometimes it is hard to find the sweet spot.

Please don't use getPeer(). As in all the examples on my site a server extension for operational behavior typically extends AbstractService, which provides getService() to get the service interfaces.

Your answer

Register or log in to post your answer.

Dashboards and work items are no longer publicly available, so some links may be invalid. We now provide similar information through other means. Learn more here.

Search context
Follow this question

By Email: 

Once you sign in you will be able to subscribe for any updates here.

By RSS:

Answers
Answers and Comments
Question details
× 10,927

Question asked: Feb 25 '15, 11:49 a.m.

Question was seen: 4,858 times

Last updated: Feb 27 '15, 10:36 a.m.

Confirmation Cancel Confirm