It's all about the answers!

Ask a question

Pass field/attributes values from java codes to RTC using JAZZ API's


0
1
Naveen S (1111) | asked Jul 14 '16, 1:53 p.m.
 

I am trying to create work item in RTC through java application using the jazz api's.

My connection to the repository is successful. Now i need to set all the required fields through java code in order to save/run the workitem. Really dont know how to set those values in below codes.

   String repositoryURI= args[0];
        String userId= args[1];
        String password= args[2];
        String projectAreaName= args[3];
        String typeIdentifier= args[4];
        String summary= args[5];
        String categoryName= args[6];

        ITeamRepository teamRepository= TeamPlatform.getTeamRepositoryService().getTeamRepository(repositoryURI);
        teamRepository.registerLoginHandler(new LoginHandler(userId, password));
        teamRepository.login(null);

        IProcessClientService processClient= (IProcessClientService) teamRepository.getClientLibrary(IProcessClientService.class);
        IAuditableClient auditableClient= (IAuditableClient) teamRepository.getClientLibrary(IAuditableClient.class);
        IWorkItemClient workItemClient= (IWorkItemClient) teamRepository.getClientLibrary(IWorkItemClient.class);

        URI uri= URI.create(projectAreaName.replaceAll(" ", "%20"));
        IProjectAreaHandle projectArea= (IProjectAreaHandle) processClient.findProcessArea(uri, null, null);
        //IProjectAreaHandle projectArea = teamArea.getProjectArea();
        if (projectArea == null) {
            System.out.println("Project area not found.");
            return false;
        }
        //IWorkItemType workItemType = service.findWorkItemType(projectArea, "defect", monitor);
        IWorkItemType workItemType= workItemClient.findWorkItemType((IProjectAreaHandle) projectArea, typeIdentifier, null);
              //  findWorkItemType(projectArea, typeIdentifier, null);
        if (workItemType == null) {
            System.out.println("Work item type not found.");
            return false;
        }
        System.out.println("Category not found.: " + categoryName );

        List path= Arrays.asList(categoryName.split("/"));

        System.out.println("Category not found.: " + path );
        ICategoryHandle category= workItemClient.findCategoryByNamePath((IProjectAreaHandle) projectArea, path, null);
        //ICategoryHandle category= 
        if (category == null) {
            System.out.println("Category not found.: " + category );
            return false;
        }


        WorkItemInitialization operation= new WorkItemInitialization(summary, category);


        IWorkItemHandle handle= operation.run(workItemType, null);

        IWorkItem workItem= auditableClient.resolveAuditable(handle, IWorkItem.FULL_PROFILE, null);

        System.out.println("Created work item " + workItem.getId() + ".");

        teamRepository.logout();
						

While running the codes i am receiving the below errors. Because of mandatory fields are not assigned. Can any one help me to pass the attribute values (Contact Phone) from java to jazz. ERROR received:

Severity: ERROR Summary: Attribute 'Contact Phone #' not set Description: The 'Contact Phone #' attribute needs to be set (work item <09:13:03>).

One answer



permanent link
Ralph Schoon (63.1k33645) | answered Jul 14 '16, 4:28 p.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
It is quite obvious from the error message, that you have to either remove required attributes or set the attributes that are required. For the latter the only guidance we can give is

https://rsjazz.wordpress.com/2013/03/20/understanding-and-using-the-rtc-java-client-api/
https://rsjazz.wordpress.com/2013/01/02/working-with-work-item-attributes/

Comments
Naveen S commented Jul 14 '16, 11:34 p.m.

Thanks for the answer, I cannot remove the required attributes and i have to set these values in java codes. Can you suggest me how to find the attribute id for the field and pass some values foe the same,
Thanks for your time.


Ralph Schoon commented Jul 15 '16, 2:31 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

All these questions are answered in the blog posts mentioned above, which are actually created to help new users of the API to get the basic understanding needed and an introduction to the most important API's. Of course that requires they actually bother with reading them if hinted to. You are searching for

workItem.getCustomAttributes();
or you look up the attribute ID in the process configuration (in the Web UI).







Naveen S commented Jul 15 '16, 7:02 a.m.

Given solution works perfectly for the textbox, however i cannot pass the field values  for the attribute which has dropdown box. (for example, I need to select the first value from the options). Please help me to sort out this issue.


Thanks for your valuable time.


Ralph Schoon commented Jul 15 '16, 7:12 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

I have provided the basic links you need. you can copy text over fine, but you will have to map other values such as enumerations as mentioned in the posts and here: https://rsjazz.wordpress.com/2012/08/20/manipulationg-work-item-enumeration-values/

Good luck.

Your answer


Register or 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.