Welcome Serena Central users! CLICK HERE
The migration of the Serena Central community is currently underway. Be sure to read THIS MESSAGE to get your new login set up to access your account.
Highlighted
Super Contributor.. AldoH Super Contributor..
Super Contributor..
278 views

How can I get the value of an additional field using SDK?

Jump to solution

Hi,

I am coding in C # to use it in an Event Processor. At the moment everything works fine with de code, but now I need to get the value of an additional field from a record. The code is executed when a record is created and I need to get the value of the additional field called "site"

I am quite new to the use of the SDK and I have not yet managed to obtain information on how to obtain the value of that field. Can someone help me?

Thank you,

0 Likes
1 Solution

Accepted Solutions
Micro Focus Expert
Micro Focus Expert

Re: How can I get the value of an additional field using SDK?

Jump to solution

Here's a basic example:

 

Record r = new Record(database, 2342);
FieldDefinition fd = new FieldDefinition(database,"Elasticky");  //String is the name of the Additional Field

Console.WriteLine("Record: " + r.Number + " (" + r.Uri + "): Elasticky Value - " + r.GetFieldValueAsString(fd, StringDisplayType.Default,false));
Console.Read();

 

Enjoy!

~Ryan Winston

View solution in original post

8 Replies
Micro Focus Expert
Micro Focus Expert

Re: How can I get the value of an additional field using SDK?

Jump to solution

Here's a basic example:

 

Record r = new Record(database, 2342);
FieldDefinition fd = new FieldDefinition(database,"Elasticky");  //String is the name of the Additional Field

Console.WriteLine("Record: " + r.Number + " (" + r.Uri + "): Elasticky Value - " + r.GetFieldValueAsString(fd, StringDisplayType.Default,false));
Console.Read();

 

Enjoy!

~Ryan Winston

View solution in original post

Super Contributor.. AldoH Super Contributor..
Super Contributor..

Re: How can I get the value of an additional field using SDK?

Jump to solution

Thank you, this was very helpful.

0 Likes
Super Contributor.. AldoH Super Contributor..
Super Contributor..

Re: How can I get the value of an additional field using SDK?

Jump to solution

Hi,

Sorry to revive the issue, but I have incorporated the code example into the code I already have and with which I have been testing.

Sorry if my question seems like a beginner, but I'm really novice with SDK and I'm learning on the go. I tried the sample code independently and it worked fine, but when I include it in the other code I am using it does not work correctly. Without the sample code, my code works fine, but if I include it, stop doing what it is supposed to do. 

Below is the complete code and would appreciate if someone can help me determine what I am doing wrong.

Thank you

Aldo

------------ Code  ------------------->>>

using HP.HPTRIM.SDK;
using System.Collections.Generic;
using System;
namespace CMaestraSitio
{
    public class RenombrarCarpetas : HP.HPTRIM.SDK.TrimEventProcessorAddIn
    {
        public override void ProcessEvent(HP.HPTRIM.SDK.Database db, HP.HPTRIM.SDK.TrimEvent eventData)
        {
            if (eventData.ObjectType == HP.HPTRIM.SDK.BaseObjectTypes.Record)
            {
                if (eventData.EventType == HP.HPTRIM.SDK.Events.ObjectAdded)
                {
 
                    HP.HPTRIM.SDK.Record record = db.FindTrimObjectByUri(HP.HPTRIM.SDK.BaseObjectTypes.Record, eventData.ObjectUri) as Record;
                    Record r = new Record(db, record.Uri);
                    FieldDefinition fd = new FieldDefinition(db, "Sitio");
                    using (System.IO.StreamWriter file = new System.IO.StreamWriter(@"C:\LogCarpetasSitio\Log.txt", true))
                    {
                        file.WriteLine("Evento " + eventData.EventType + "  Fecha " + record.DateCreated + "  Registro Uri " + record.Uri
                                 + "  Registro Titulo " + record.Title + "  Registro Nombre " + record.Name + "  Tipo Registro Uri " + record.RecordType.Uri 
                                 + "  Tipo Registro Name " + record.RecordType.Name + "  Contenedor Uri " + record.Container.Uri + "  Contenedor Titulo " + record.Container.Title
                                 + "  Valor de Sitio " + r.GetFieldValueAsString(fd, StringDisplayType.Default, false));
                    }
              
                    if (record != null)
                    {
                        if (record.RecordType.Uri == 1)
                        {
                            string contname = record.Container.Title;
                            // Buscar guión medio en su segunda ocurrencia
                            int count = 0;
                            int n = 2;
                            int indexmdash = 0;
                            for (int i = 0; i < contname.Length; i++)
                            {
                                if (contname[i] == '-')
                                {
                                    count++;
                                    if (count == n)
                                    {
                                        indexmdash = i;
                                    }
                                }
                            }
                            string sitio = contname.Substring(indexmdash + 2);
                            string notestring = "Record type " + record.RecordType.Name + "Container " + record.Container.Name + " Container uri " + record.Container.Uri
                                                 + " event fired";
                            string titlenew = record.Title;
                            TrimMainObjectSearch objSearch = new TrimMainObjectSearch(db, BaseObjectTypes.Record);
                            objSearch.SetSearchString("Container:" + record.Container.Uri.UriAsString);
                            record.SetNotes(notestring, NotesUpdateType.AppendWithUserStamp);
                            if (record.Title == "Lanzamiento Comercial del Sitio de Celda")
                            {
                                titlenew = titlenew + " " + sitio;
                                record.Title = titlenew;
                            }
                            record.Save();
                        }
                    }
                }
            }
        }
    }
}
0 Likes
Micro Focus Expert
Micro Focus Expert

Re: How can I get the value of an additional field using SDK?

Jump to solution

 Record r = new Record(db, record.Uri); 

Is likely redundant since record is already created.  You also have to ensure that the Sitio field has been populated.

So, verify that field exists outside of WriteLine, and proceed accordingly based on whether or not the field has been populated previously.

Are you new to programming or just the CM SDK?  Ultimately, you need to debug your code until you find the culprit and adjust the code as necessary, via logging or manual debug messages.

0 Likes
Super Contributor.. AldoH Super Contributor..
Super Contributor..

Re: How can I get the value of an additional field using SDK?

Jump to solution
Hi

Thanks for your help. I will proceed as you tell me.
I have some knowledge about programming but I am not an expert and about the Sdk I had no previous experience. In my work, due to the needs of the processes with Records Manager I have found myself in the need to start working with Sdk and I am learning on the fly, researching and seeking help in the forum.
Really thank you very much for your help.
0 Likes
Micro Focus Expert
Micro Focus Expert

Re: How can I get the value of an additional field using SDK?

Jump to solution
My pleasure. I recommend that unless you hit snags in the function of the SDK, to post comments here and request that open Support cases about programming be closed out (i'm the one you'd get in the AMS region 🙂 )
0 Likes
Super Contributor.. AldoH Super Contributor..
Super Contributor..

Re: How can I get the value of an additional field using SDK?

Jump to solution
Thank you. I will proceed that way.
0 Likes
Super Contributor.. AldoH Super Contributor..
Super Contributor..

Re: How can I get the value of an additional field using SDK?

Jump to solution

Hi,

I finally achieved the goal. Now it is working correctly even if I massively import folders with DataPort, the code does its job well.I share the code I am using. If you had any suggestions to improve it, I would appreciate any suggestions you can make.

Again thank you very much.

using HP.HPTRIM.SDK;
using System.Collections.Generic;
using System;
namespace CMaestraSitio
{
    public class RenombrarCarpetas : HP.HPTRIM.SDK.TrimEventProcessorAddIn
    {
        public static string sitio { get; set; } = string.Empty;
        public static string titlenew { get; set; } = string.Empty;
        public override void ProcessEvent(HP.HPTRIM.SDK.Database db, HP.HPTRIM.SDK.TrimEvent eventData)
        {
            if (eventData.ObjectType == HP.HPTRIM.SDK.BaseObjectTypes.Record)
            {
                if (eventData.EventType == HP.HPTRIM.SDK.Events.ObjectAdded)
                {
                    HP.HPTRIM.SDK.Record record = db.FindTrimObjectByUri(HP.HPTRIM.SDK.BaseObjectTypes.Record, eventData.ObjectUri) as Record;
                    if (record != null)
                    {
                        if (record.RecordType.Uri == 1)
                        {
                            if (record.Title == "Lanzamiento Comercial del Sitio de Celda")
                            {
                                Record objRecord = new Record(db, record.Container.Uri);
                                FieldDefinition field = new FieldDefinition(db, "Sitio");
                                UserFieldValue userField = objRecord.GetFieldValue(field);
                                sitio = Convert.ToString(userField);
                                titlenew = record.Title + " " + sitio;
                                record.Title = titlenew;
                            }
                            string notestring = "Record type " + record.RecordType.Name + "Container " + record.Container.Name + " Container uri " + record.Container.Uri + " event fired";
                            TrimMainObjectSearch objSearch = new TrimMainObjectSearch(db, BaseObjectTypes.Record);
                            objSearch.SetSearchString("Container:" + record.Container.Uri.UriAsString);
                            record.SetNotes(notestring, NotesUpdateType.AppendWithUserStamp);
                            record.Save();
                        }
                    }
                }
            }
        }
    }
}
0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.