cancel

Get Userdefined field from trim

SOLVED
Go to solution
Highlighted
shunil
Regular Contributor.

Get Userdefined field from trim

Hey Guys,

I am using Service API to communicate with Trim. I am working on grabing metadata from trim and in some part I have been succesful. I am facing trouble get extracting boolean format userdefined field espacially "PUBLICLY AVAILABLE". I am succesfully extracting Userdefined fields without any trouble but when the fields are Boolean type all I get is null value. I have researched the trim community for knowledge but haven't got any definitive solution. I will attach my code snnipet.

If I could get any help it would be very helpful.

Here is the code snippet:

  RecordFind r = new RecordFind()
            {
                Id = recordId,//uri

                Properties = new PropertyList("Author", "PUBLICLYAVAILABLE","STATUS"),

                PropertyValue = PropertyType.Both,
               StringDisplayType = StringDisplayType.Default

}

 var response = trimClient.Get<RecordsResponse>(r);

In above snippet,STATUS is one of the UserDefinedField which I can extract with same code but PUBLICLYAVAILABLE  is always null when I know that its value is "YES".

Thank You.

 

 

6 REPLIES
David Churchland
Acclaimed Contributor.
Solution

Re: Get Userdefined field from trim

Which version of RM are you using?


Blog | Samples | HPE CM 9.1 SDK Docs
**Any opinions expressed in this forum are my own personal opinion and should not be interpreted as an official statement on behalf of MicroFocus**
shunil
Regular Contributor.

Re: Get Userdefined field from trim

Hi,

I am working on trim version "8.1.1.7919".

I got the information with a workaround which is not very plesant. I am using Service Api with soap in c# to get the things done.

If you could point to right direction it would be helpful.

Thank you

David Churchland
Acclaimed Contributor.

Re: Get Userdefined field from trim

I should have investigated more closely, the original reply I wrote here was incorrect, stay tuned...


Blog | Samples | HPE CM 9.1 SDK Docs
**Any opinions expressed in this forum are my own personal opinion and should not be interpreted as an official statement on behalf of MicroFocus**
shunil
Regular Contributor.

Re: Get Userdefined field from trim

Thanks for looking into it. I found out that this situation persist for Boolean fields.

David Churchland
Acclaimed Contributor.

Re: Get Userdefined field from trim

The good news is that (I believe) the data is being returned from the service, it is just getting lost in the deserializtion.  So try this...

Add this method to your class:

        private static T ToDictionary<T, P>(string json) where T : System.Collections.IDictionary
        {
            T dictionary = Activator.CreateInstance<T>();

            JsonObject jObject = JsonObject.Parse(json);

            foreach (string key in jObject.Keys)
            {
                dictionary.Add(key, jObject.Get<P>(key));
            }

            return dictionary;
        }

The after you instantiate the TrimClient wire up the deserializer for the Field Dictionary, like this:

TrimClient trimClient = new TrimClient("http://myserver/ServiceAPI");
...

JsConfig<Dictionary<string, ITrimProperty>>.RawDeserializeFn = (val) => { return ToDictionary<Dictionary<string, ITrimProperty>, ITrimProperty>(val); };

 


Blog | Samples | HPE CM 9.1 SDK Docs
**Any opinions expressed in this forum are my own personal opinion and should not be interpreted as an official statement on behalf of MicroFocus**
David Churchland
Acclaimed Contributor.

Re: Get Userdefined field from trim

*** UPDATE ***

I am having a bad day, I just re-tested and the code below has no affect, in fact in my 8.1.1 everything works fine.  I shall go back to the first thing I was going to say.  Are you sure you are fetching the correct Record?  If the RecordFind.Id is numeric then it will find the Record with either that Uri or Number.  Is it possible you are returning the wrong Record?  Try doing a search instead of a find, for example:

Records request = new Records()
{
      q = "number:2",
       Properties = new PropertyList("PUBLICLYAVAILABLE", "NUM")
};

Blog | Samples | HPE CM 9.1 SDK Docs
**Any opinions expressed in this forum are my own personal opinion and should not be interpreted as an official statement on behalf of MicroFocus**