SDK getCustomFieldTypes returns empty objects

Description
Jameous
Posts: 4
Joined: Thu Dec 07, 2017 9:01 pm

SDK getCustomFieldTypes returns empty objects

Postby Jameous » Thu Dec 07, 2017 9:25 pm

Working in C# using the seabay.polarion.WSConnector library.

I am trying to retrieve the list of CustomFieldTypes for a WorkItem. I have successfully retrieved the Project and the WorkItem, so I know I can communicate with the server. When I execute getCustomFieldTypes with the WorkItem it returns an array of CustomFieldTypes that is the correct length. However, when I attempt to access the attributes of one of the CustomFieldTypes (Ex. id or name), they are all null.

I wrote similar code in Python using the suds SOAP client and I can read all of the attributes correctly.

What am I missing?

rpn
Posts: 17
Joined: Thu Oct 26, 2017 4:08 pm

Re: SDK getCustomFieldTypes returns empty objects

Postby rpn » Fri Dec 08, 2017 2:15 pm

Try casting to EnumOptionId[], if it is a multi-value field.
something like
if(cf.value is net.seabay.polarion.Tracker.EnumOptionId[])
foreach (var val in (net.seabay.polarion.Tracker.EnumOptionId[])cf.value

Hope that helps, I can read CustomFields in my project that way.
(EDIT: I retrieve the workitem by getWorkitemsWithFields, and just query for the customFields of the WI)
No native speaker, sorry for my bad English.

Jameous
Posts: 4
Joined: Thu Dec 07, 2017 9:01 pm

Re: SDK getCustomFieldTypes returns empty objects

Postby Jameous » Fri Dec 08, 2017 3:34 pm

Thanks for that suggestion rpn.

Unfortunately, I am still having trouble. The method you described is good for reading the EnumOptionIds from a work item's customFields attribute. I am trying to find the definition for the custom fields using the Tracker function getCustomFieldTypes which returns a CustomFieldType array. That definition gives me the enumId for the field so I can then call getAllEnumOptionsForId to get the possible values for the field.

I also tried getDefinedCustomFieldTypes, but I get a permission error on that one.

I must be close since getCustomFieldTypes does return a correctly sized array of CustomFieldType, there is just the problem of the CustomFieldTypes not being initialized.

Here is the code I have been testing with.

Code: Select all

WorkItem[] workItems = TrackerClient.queryWorkItems(string.Format("project.id:{0} AND id:XX-XXXX", projects[0].id), "id", Fields);
CustomFieldType[] customFields = TrackerClient.getCustomFieldTypes(workItems[0].uri);

foreach (CustomFieldType cft in customFields)
{
    Console.WriteLine("CustomFieldType");
    Console.WriteLine("Name: {0}\nName is null: {1}", cft.name, cft.name == null);
    Console.WriteLine("Id: {0}\nId is null: {1}", cft.id, cft.id == null);
    if (cft is EnumCustomFieldType)
    {
        EnumCustomFieldType ecft = (EnumCustomFieldType)cft;
        Console.WriteLine("EnumCustomFieldType");
        Console.WriteLine("Name: {0}\nName is null: {1}", ecft.name, ecft.name == null);
        Console.WriteLine("Id: {0}\nId is null: {1}", ecft.id, ecft.id == null);
    }
}


The output shows all Name and Id attributes on all CustomFieldTypes to be null.

adbarads
Posts: 5
Joined: Mon Nov 13, 2017 7:47 pm

Re: SDK getCustomFieldTypes returns empty objects

Postby adbarads » Fri Dec 22, 2017 6:28 am

I am having the same issue. When the custom field I have is empty. When I do a getCustomField() it returns null.
I don't know how to create the object and go ahead and use the setCustomField(). That method appears to take the key for the custom field and the object. But the object is not returned from the getCustomField().

Any thoughts?

ALMighty
Posts: 80
Joined: Wed Apr 27, 2016 10:34 am
Location: Austria

Re: SDK getCustomFieldTypes returns empty objects

Postby ALMighty » Mon Jan 08, 2018 6:55 pm

Regarding your code:

Jameous wrote:

Code: Select all

WorkItem[] workItems = TrackerClient.queryWorkItems(string.Format("project.id:{0} AND id:XX-XXXX", projects[0].id), "id", Fields);
CustomFieldType[] customFields = TrackerClient.getCustomFieldTypes(workItems[0].uri);

foreach (CustomFieldType cft in customFields)
{
    Console.WriteLine("CustomFieldType");
    Console.WriteLine("Name: {0}\nName is null: {1}", cft.name, cft.name == null);
    Console.WriteLine("Id: {0}\nId is null: {1}", cft.id, cft.id == null);
    if (cft is EnumCustomFieldType)
    {
        EnumCustomFieldType ecft = (EnumCustomFieldType)cft;
        Console.WriteLine("EnumCustomFieldType");
        Console.WriteLine("Name: {0}\nName is null: {1}", ecft.name, ecft.name == null);
        Console.WriteLine("Id: {0}\nId is null: {1}", ecft.id, ecft.id == null);
    }
}


The output shows all Name and Id attributes on all CustomFieldTypes to be null.


I use the Polarion API via Java but I think in this case it is similar to C#.
I noticed that you try to access/read/select the attributes/field/variables
of the CustomFieldType object/instance directly.

However I think you have to use the Getter methods (see the Javadoc here of the CustomFieldType class, I think they are similar in C#)

I wrote quick example in java which illustrates this, you also can see it attached (press right-click on the image for getting the options to enlarge it):

Code: Select all

// Note: polarionconnection is an own implementation of mine holding the WebServiceFactory
      CustomFieldType[] cfTypes = polarionconnection.getTrackerWebService().getCustomFieldTypes(testcase.getUri());
      
      for(int cNR = 0; cNR < cfTypes.length; cNR++)
      {
         
         System.out.println("Custom Field nr. " + cNR +" - id: " + cfTypes[cNR].getId() ); // right, value can be read
         
         System.out.println("Custom Field nr. " + cNR +" - id: " + cfTypes[cNR].id ); // wrong, returns an error
         
         System.out.println("Custom Field nr. " + cNR +" - name: " + cfTypes[cNR].getName() );
         System.out.println("Custom Field nr. " + cNR +" - type: " + cfTypes[cNR].getType() );
      } // end for


The author in this thread seemed to have a similar problem but with setting the variables instead.
I always recommend to use the Get(ter) and Set(ter) methods whenever possible.
Attachments
Polarion_SOAP_API_Java_selecting_CustomFieldType_field_not_possible_without_Getter_Methods.png
Example that shows that you cannot read the fields of the objects of the Polarion API directly, you have to use setters.
Polarion_SOAP_API_Java_selecting_CustomFieldType_field_not_possible_without_Getter_Methods.png (59.82 KiB) Viewed 1503 times
---------------------------------------------------------------------------------------------------
Playing a good game is never lame. :D
Image

Jameous
Posts: 4
Joined: Thu Dec 07, 2017 9:01 pm

Re: SDK getCustomFieldTypes returns empty objects

Postby Jameous » Mon Jan 08, 2018 7:27 pm

Thanks @ALMighty,

Unfortunately, I don't see the getter methods defined in the library. The SOAP object definition for CustomFieldType in the library looks like this:

Code: Select all

public partial class CustomFieldType : object, System.ComponentModel.INotifyPropertyChanged {
       // Attributes
       private string idField;
       // etc...
   
       //Properties
       public string id {
            get {
                return this.idField;
            }
            set {
                this.idField = value;
                this.RaisePropertyChanged("id");
            }
        }
        // etc...
}


There is no getID method in that class. In fact, the only method is RaisePropertyChanged. If I try to execute getName/getId anyway I get an exception:

Code: Select all

"'CustomFieldType' does not contain a definition for 'getName' and no extension method 'getName' accepting a first argument of type 'CustomFieldType' could be found (are you missing a using directive or an assembly reference?)"


Since I was able to use the interface with Python without defining the types I am wondering if I could find a generic SOAP client for C# that would discover the types (such as CustomFieldType) automatically.

ALMighty
Posts: 80
Joined: Wed Apr 27, 2016 10:34 am
Location: Austria

Re: SDK getCustomFieldTypes returns empty objects

Postby ALMighty » Wed Jan 10, 2018 3:26 pm

Jameous wrote:Thanks @ALMighty,

Unfortunately, I don't see the getter methods defined in the library.



I am sorry, obvioulsy for C# the classe shave a different structure that is not like the classes in Java, my bad. :oops:

However concerning your code before:

Jameous wrote:

Code: Select all

WorkItem[] workItems = TrackerClient.queryWorkItems(string.Format("project.id:{0} AND id:XX-XXXX", projects[0].id), "id", Fields);
CustomFieldType[] customFields = TrackerClient.getCustomFieldTypes(workItems[0].uri);

foreach (CustomFieldType cft in customFields)
{
    Console.WriteLine("CustomFieldType");
    Console.WriteLine("Name: {0}\nName is null: {1}", cft.name, cft.name == null);
    Console.WriteLine("Id: {0}\nId is null: {1}", cft.id, cft.id == null);
    if (cft is EnumCustomFieldType)
    {
        EnumCustomFieldType ecft = (EnumCustomFieldType)cft;
        Console.WriteLine("EnumCustomFieldType");
        Console.WriteLine("Name: {0}\nName is null: {1}", ecft.name, ecft.name == null);
        Console.WriteLine("Id: {0}\nId is null: {1}", ecft.id, ecft.id == null);
    }
}


The output shows all Name and Id attributes on all CustomFieldTypes to be null.


You are really sure that the datatype is really called EnumCustomFieldType for fields that bear an enumeration option or this a placeholder you defined for yourself? :?

In the API I use with Java, the data type is called EnumOptionId.

Here is a similar Java code snippet than before but now with trying to find out if the field bears an enum value or if its datatype is something else, maybe you could tranform this for your C# application :wink:

Code: Select all

CustomFieldType[] cfTypes = polarionconnection.getTrackerWebService().getCustomFieldTypes(testcase.getUri());
      
for(int cNR = 0; cNR < cfTypes.length; cNR++)
{
   if(cfTypes[cNR].getType().toString().contains("EnumOptionId"))
   {
      System.out.println("Yes, this is as enumoption");
   } // end if    
} // end for
   
---------------------------------------------------------------------------------------------------
Playing a good game is never lame. :D
Image

Jameous
Posts: 4
Joined: Thu Dec 07, 2017 9:01 pm

Re: SDK getCustomFieldTypes returns empty objects

Postby Jameous » Wed Jan 10, 2018 4:19 pm

Thanks again ALMighty.

That is interesting. I modified my code to print out

Code: Select all

cft.GetType().ToString()

on each iteration and each one either prints "net.seabay.polarion.Tracker.CustomFieldType" or "net.seabay.polarion.Tracker.EnumCustomFieldType". So the Java and C# libraries must be significantly different if my getCustomFieldTypes returns a list of CustomFieldTypes and yours returns a list of EnumOptionIds

If I remember correctly, the EnumCustomFieldType thing was part of my debugging. Since the fields I am looking at are actually defined as EnumCustomFieldTypes I though maybe casting the CustomFieldTypes to EnumCustomFieldTypes would make the fields accessible .I suppose I should mention I didn't create the fields and I have limited experience with that side of Polarion. I was just asked to write an application to extract some data from Polarion.

In Python, I can get the custom fields using getCustomFieldTypes and print them out and I get a list of items that look like this:

Code: Select all

(EnumCustomFieldType){
  defaultValue = None
  dependsOn = None
  description = None
  enumId = "SomeEnumId"
  id = "SomeFieldId"
  multi = False
  name = "SomeFieldName"
  required = False
  type = "ns1:EnumOptionId"
}


There are some items in the list returned by getCustomFieldTypes that are CustomFieldTypes rather than EnumCustomFieldTypes but all the fields I am interested in are EnumCustomFieldTypes. My process (in Python) has been to go through the list and for each one I am interested in I take that enumId and pass that to getAllEnumOptionsForId to get the possible values for the field.


Return to “Polarion Application Lifecycle Management (ALM)”

Who is online

Users browsing this forum: No registered users and 6 guests