Highlighted
Frequent Contributor.. Frequent Contributor..
Frequent Contributor..
149 views

get value from look up custom property with sdk

Jump to solution

Hi everyone,

I have record type which includes +10000 records. I want to get these records via CM SDK. I used lookup values for some of the custom properties but when i try to get values from these custom properties CM SDK returns me uriid of these look up values not the actual values. How can i get the actual values?

Here is my code;

this is the class which i want to fill properties with return values.

public class GDPRInventory
{
public String Title { get; set; }
public String AktarimAmaci { get; set; }
public String BirincilveyaİkincilKisiselVerimi { get; set; }
public String Direktorluk { get; set; }
public String EkAciklamalar { get; set; }
public String GrupMudurlugu { get; set; }
public String IslemeAmaci { get; set; }
public String IslenenKisiselVeri { get; set; }
public String KVKKKapsamindaDayanakIstisnaMaddesi { get; set; }
public String KVKKKapsamindaDayanakKanunIlgiliDuzenleme { get; set; }
public String Mudurluk { get; set; }
public String OzelNitelikliKisiselVerimi { get; set; }
public String PaylasilanSirketKurumKisi { get; set; }
public String SaklamaSuresiBaslangici { get; set; }
public String SilmeAnonimlestirmeProseduruUygulanıyorMu { get; set; }
public String TercihEdilenKisiselVeriImhaYontemi { get; set; }
public String TutulmasıGerekliAzamiSure { get; set; }
public String UygulamaAdi { get; set; }
public String VarsaAlinanGuvenlikOnlemleri { get; set; }
public String VarsaYasalSaklamaIleIlgiliMevzuat { get; set; }
public String VarsaYurtdisiAliciUlkeler { get; set; }
public String VeriKategorisi { get; set; }
public String VeriKonusuKisiGrubu { get; set; }
public String VeriSahibiGrupSirket { get; set; }
public String VerininKullanimAmacinaIliskinDetayliAciklama { get; set; }
public String VerininTutulduguAlindigiOrtam { get; set; }
}

 

******************************************************************

 

this is the class for holding name of the custom properties of this record type

public class GDPRInventoryFields
{
public static string TitleField = "Title (Free Text Part)";
public static string AktarimAmaciField = "Aktarim Amaci";
public static string BirincilveyaİkincilKisiselVerimiField = "Birincil veya Ikincil Kisisel Veri Mi?";
public static string DirektorlukField = "Direktorluk";
public static string EkAciklamalarField = "Ek Aciklamalar";
public static string GrupMudurluguField = "Grup Mudurlugu";
public static string IslemeAmaciField = "Isleme Amaci";
public static string IslenenKisiselVeriField = "Islenen Kisisel Veri";
public static string KVKKKapsamindaDayanakIstisnaMaddesiField = "KVKK Kapsaminda Dayanak Istisna Maddesi";
public static string KVKKKapsamindaDayanakKanunIlgiliDuzenlemeField = "KVKK Kapsaminda Dayanak Kanun-Ilgili Duzenleme";
public static string MudurlukField = "Mudurluk";
public static string OzelNitelikliKisiselVerimiField = "Ozel Nitelikli Kisisel Veri Mi?";
public static string PaylasilanSirketKurumKisiField = "Paylasilan Sirket-Kurum-Kisi";
public static string SaklamaSuresiBaslangiciField = "Saklama Suresi Baslangici";
public static string SilmeAnonimlestirmeProseduruUygulanıyorMuField = "Silme-Anonimlestirme Proseduru Uygulanıyor Mu?";
public static string TercihEdilenKisiselVeriImhaYontemiField = "Tercih Edilen Kisisel Veri Imha Yontemi";
public static string TutulmasıGerekliAzamiSure = "Tutulması Gerekli Azami Sure";
public static string UygulamaAdiField = "Uygulama Adi";
public static string VarsaAlinanGuvenlikOnlemleriField = "Varsa Alinan Guvenlik Onlemleri";
public static string VarsaYasalSaklamaIleIlgiliMevzuatField = "Varsa Yasal Saklama Ile Ilgili Mevzuat";
public static string VarsaYurtdisiAliciUlkelerField = "Varsa Yurtdisi Alici Ulkeler";
public static string VeriKategorisiField = "Veri Kategorisi";
public static string VeriKonusuKisiGrubuField = "Veri Konusu Kisi Grubu";
public static string VeriSahibiGrupSirketField = "Veri Sahibi Grup Sirket";
public static string VerininKullanimAmacinaIliskinDetayliAciklamaField = "Veri Kullanımına Iliskin Detayli Aciklama";
public static string VerininTutulduguAlindigiOrtamField = "Verinin Tutuldugu-Alindigi Ortam";
}

 

And this is the code for using get the values and fill the class properties.

 

static void Main(string[] args)
{
//log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
try
{
Database objDB = new Database();
objDB.Id = Helper.GetConfigParamValueOrThrowException("CMDatabaseID"); //every HPE Content Manager Database has a two character id
objDB.WorkgroupServerName = Helper.GetConfigParamValueOrThrowException("WorkGroupServerName");

if (!objDB.IsConnected)
{
objDB.Connect();
}

TrimMainObjectSearch objSearch = new TrimMainObjectSearch(objDB, BaseObjectTypes.Record);
objSearch.SetFilterString("type:KisiselVeriEnvanteri");
objSearch.SetSortString("createdOn");
List<GDPRInventory> list = new List<GDPRInventory>();

int i = 1;

foreach (Record objRec in objSearch)
{
try
{
GDPRInventory inventory = new GDPRInventory();

var userFields = objRec.RecordType.UserFields;

inventory.AktarimAmaci = objRec.GetFieldValue(userFields.FirstOrDefault(t => t.Name.Equals(GDPRInventoryFields.AktarimAmaciField))).ToString();
inventory.BirincilveyaİkincilKisiselVerimi = objRec.GetFieldValue(userFields.FirstOrDefault(t => t.Name.Equals(GDPRInventoryFields.BirincilveyaİkincilKisiselVerimiField))).ToString();
inventory.Direktorluk = objRec.GetFieldValue(userFields.FirstOrDefault(t => t.Name.Equals(GDPRInventoryFields.DirektorlukField))).ToString();
inventory.EkAciklamalar = objRec.GetFieldValue(userFields.FirstOrDefault(t => t.Name.Equals(GDPRInventoryFields.EkAciklamalarField))).ToString();
inventory.GrupMudurlugu = objRec.GetFieldValue(userFields.FirstOrDefault(t => t.Name.Equals(GDPRInventoryFields.GrupMudurluguField))).ToString();
inventory.IslemeAmaci = objRec.GetFieldValue(userFields.FirstOrDefault(t => t.Name.Equals(GDPRInventoryFields.IslemeAmaciField))).ToString();
inventory.IslenenKisiselVeri = objRec.GetFieldValue(userFields.FirstOrDefault(t => t.Name.Equals(GDPRInventoryFields.IslenenKisiselVeriField))).ToString();
inventory.KVKKKapsamindaDayanakIstisnaMaddesi = objRec.GetFieldValue(userFields.FirstOrDefault(t => t.Name.Equals(GDPRInventoryFields.KVKKKapsamindaDayanakIstisnaMaddesiField))).ToString();
inventory.KVKKKapsamindaDayanakKanunIlgiliDuzenleme = objRec.GetFieldValue(userFields.FirstOrDefault(t => t.Name.Equals(GDPRInventoryFields.KVKKKapsamindaDayanakKanunIlgiliDuzenlemeField))).ToString();
inventory.Mudurluk = objRec.GetFieldValue(userFields.FirstOrDefault(t => t.Name.Equals(GDPRInventoryFields.MudurlukField))).ToString();
inventory.OzelNitelikliKisiselVerimi = objRec.GetFieldValue(userFields.FirstOrDefault(t => t.Name.Equals(GDPRInventoryFields.OzelNitelikliKisiselVerimiField))).ToString();
inventory.PaylasilanSirketKurumKisi = objRec.GetFieldValue(userFields.FirstOrDefault(t => t.Name.Equals(GDPRInventoryFields.PaylasilanSirketKurumKisiField))).ToString();
inventory.SaklamaSuresiBaslangici = objRec.GetFieldValue(userFields.FirstOrDefault(t => t.Name.Equals(GDPRInventoryFields.SaklamaSuresiBaslangiciField))).ToString();
inventory.SilmeAnonimlestirmeProseduruUygulanıyorMu = objRec.GetFieldValue(userFields.FirstOrDefault(t => t.Name.Equals(GDPRInventoryFields.SilmeAnonimlestirmeProseduruUygulanıyorMuField))).ToString();
inventory.TercihEdilenKisiselVeriImhaYontemi = objRec.GetFieldValue(userFields.FirstOrDefault(t => t.Name.Equals(GDPRInventoryFields.TercihEdilenKisiselVeriImhaYontemiField))).ToString();
//inventory.Title = objRec.GetFieldValue(userFields.FirstOrDefault(t => t.Name.Equals(GDPRInventoryFields.TitleField)).ToString();
inventory.TutulmasıGerekliAzamiSure = objRec.GetFieldValue(userFields.FirstOrDefault(t => t.Name.Equals(GDPRInventoryFields.TutulmasıGerekliAzamiSure))).ToString();
inventory.UygulamaAdi = objRec.GetFieldValue(userFields.FirstOrDefault(t => t.Name.Equals(GDPRInventoryFields.UygulamaAdiField))).ToString();
inventory.VarsaAlinanGuvenlikOnlemleri = objRec.GetFieldValue(userFields.FirstOrDefault(t => t.Name.Equals(GDPRInventoryFields.VarsaAlinanGuvenlikOnlemleriField))).ToString();
inventory.VarsaYasalSaklamaIleIlgiliMevzuat = objRec.GetFieldValue(userFields.FirstOrDefault(t => t.Name.Equals(GDPRInventoryFields.VarsaYasalSaklamaIleIlgiliMevzuatField))).ToString();
inventory.VarsaYurtdisiAliciUlkeler = objRec.GetFieldValue(userFields.FirstOrDefault(t => t.Name.Equals(GDPRInventoryFields.VarsaYurtdisiAliciUlkelerField))).ToString();
inventory.VeriKategorisi = objRec.GetFieldValue(userFields.FirstOrDefault(t => t.Name.Equals(GDPRInventoryFields.VeriKategorisiField))).ToString();
inventory.VeriKonusuKisiGrubu = objRec.GetFieldValue(userFields.FirstOrDefault(t => t.Name.Equals(GDPRInventoryFields.VeriKonusuKisiGrubuField))).ToString();
inventory.VerininKullanimAmacinaIliskinDetayliAciklama = objRec.GetFieldValue(userFields.FirstOrDefault(t => t.Name.Equals(GDPRInventoryFields.VerininKullanimAmacinaIliskinDetayliAciklamaField))).ToString();
inventory.VerininTutulduguAlindigiOrtam = objRec.GetFieldValue(userFields.FirstOrDefault(t => t.Name.Equals(GDPRInventoryFields.VerininTutulduguAlindigiOrtamField))).ToString();
inventory.VeriSahibiGrupSirket = objRec.GetFieldValue(userFields.FirstOrDefault(t => t.Name.Equals(GDPRInventoryFields.VeriSahibiGrupSirketField))).ToString();

list.Add(inventory);
Console.WriteLine(list.Count + " " + i++);
}
catch(Exception ex)
{
Console.WriteLine(ex.StackTrace, ex);
Console.WriteLine(ex.Message, ex);
Console.WriteLine(list.Count + " " + i++);
continue;
}
}
objDB.Dispose();
Console.ReadLine();
}
catch (Exception ex)
{
Console.WriteLine(ex.StackTrace, ex);
Console.WriteLine(ex.Message, ex);
}
}
}

 

I also attached the code in txt file.

Thank you.

0 Likes
1 Solution

Accepted Solutions
Highlighted
Micro Focus Expert
Micro Focus Expert

Re: get value from look up custom property with sdk

Jump to solution

As you have observed the value of a field is an object, not a string.  There are a variety of ways to get the name of the LookupItem object.

In the sample below I:

  1. use ToString() which returns the Uri
  2. cast the object to LookupItem and then get the Name property
  3. use Record.GetFieldValueAsString().  One advantage with this method is that it formats the string appropriately for the context, Grid, ViewPane etc.

 

Record rec = new Record(database, "REC_221");

FieldDefinition fieldDef = new FieldDefinition(database, "Visibility");

var val = rec.GetFieldValue(fieldDef);

Console.WriteLine(val.ToString());
Console.WriteLine((val.AsTrimObject() as LookupItem).Name);

string stringVal = rec.GetFieldValueAsString(fieldDef, StringDisplayType.TreeColumn, false);

Console.WriteLine(stringVal);

 

 

 


Blog | Samples | CM 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**

View solution in original post

2 Replies
Highlighted
Micro Focus Expert
Micro Focus Expert

Re: get value from look up custom property with sdk

Jump to solution

As you have observed the value of a field is an object, not a string.  There are a variety of ways to get the name of the LookupItem object.

In the sample below I:

  1. use ToString() which returns the Uri
  2. cast the object to LookupItem and then get the Name property
  3. use Record.GetFieldValueAsString().  One advantage with this method is that it formats the string appropriately for the context, Grid, ViewPane etc.

 

Record rec = new Record(database, "REC_221");

FieldDefinition fieldDef = new FieldDefinition(database, "Visibility");

var val = rec.GetFieldValue(fieldDef);

Console.WriteLine(val.ToString());
Console.WriteLine((val.AsTrimObject() as LookupItem).Name);

string stringVal = rec.GetFieldValueAsString(fieldDef, StringDisplayType.TreeColumn, false);

Console.WriteLine(stringVal);

 

 

 


Blog | Samples | CM 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**

View solution in original post

Highlighted
Frequent Contributor.. Frequent Contributor..
Frequent Contributor..

Re: get value from look up custom property with sdk

Jump to solution

Hi,

Thank you for your advise. I implemented 3rd option and it worked.

Thank you again.

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.