Marilou Trusted Contributor.
Trusted Contributor.
204 views

SDK 9.2: How to get a specific custom field value of parent accession?

Jump to solution

SDK 9.2: How to get a specific custom field value of parent accession and assign it to the child record series?

0 Likes
1 Solution

Accepted Solutions
Highlighted
Micro Focus Expert
Micro Focus Expert

Re: SDK 9.2: How to get a specific custom field value of parent accession?

Jump to solution

Something like this should do it.

TrimMainObjectSearch search = new TrimMainObjectSearch(db, BaseObjectTypes.Record);
TrimSearchClause clause = new TrimSearchClause(db, BaseObjectTypes.Record, SearchClauseIds.RecordAccession);
clause.SetCriteriaFromString("1");

search.AddSearchClause(clause);

if (search.FastCount != 1)
{
	// if it is a problem that there is more than one Record with this accession number throw an exception here...
}

FieldDefinition myFieldDef = new FieldDefinition(db, "test");

foreach (Record record in search)
{
	var fieldValue = record.GetFieldValue(myFieldDef);

	TrimMainObjectSearch seriesSearch = new TrimMainObjectSearch(db, BaseObjectTypes.Record);
	TrimSearchClause seriesClause = new TrimSearchClause(db, BaseObjectTypes.Record, SearchClauseIds.RecordInSeries);
	seriesClause.SetCriteriaFromObject(record);
	seriesSearch.AddSearchClause(seriesClause);

	foreach (Record seriesDocument in seriesSearch)
	{
		seriesDocument.SetFieldValue(myFieldDef, fieldValue);
		seriesDocument.Save();
	}
}

Blog | Samples | HPE CM 9.3 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**
0 Likes
3 Replies
Micro Focus Expert
Micro Focus Expert

Re: SDK 9.2: How to get a specific custom field value of parent accession?

Jump to solution

Are you saying you want to:

  1. find a Record by accession number,
  2. retrieve the value of one of its custom fields, then
  3. apply that value to the custom field on all records in the series?

Blog | Samples | HPE CM 9.3 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**
0 Likes
Marilou Trusted Contributor.
Trusted Contributor.

Re: SDK 9.2: How to get a specific custom field value of parent accession?

Jump to solution

Yes that is what I wanted to do.

0 Likes
Highlighted
Micro Focus Expert
Micro Focus Expert

Re: SDK 9.2: How to get a specific custom field value of parent accession?

Jump to solution

Something like this should do it.

TrimMainObjectSearch search = new TrimMainObjectSearch(db, BaseObjectTypes.Record);
TrimSearchClause clause = new TrimSearchClause(db, BaseObjectTypes.Record, SearchClauseIds.RecordAccession);
clause.SetCriteriaFromString("1");

search.AddSearchClause(clause);

if (search.FastCount != 1)
{
	// if it is a problem that there is more than one Record with this accession number throw an exception here...
}

FieldDefinition myFieldDef = new FieldDefinition(db, "test");

foreach (Record record in search)
{
	var fieldValue = record.GetFieldValue(myFieldDef);

	TrimMainObjectSearch seriesSearch = new TrimMainObjectSearch(db, BaseObjectTypes.Record);
	TrimSearchClause seriesClause = new TrimSearchClause(db, BaseObjectTypes.Record, SearchClauseIds.RecordInSeries);
	seriesClause.SetCriteriaFromObject(record);
	seriesSearch.AddSearchClause(seriesClause);

	foreach (Record seriesDocument in seriesSearch)
	{
		seriesDocument.SetFieldValue(myFieldDef, fieldValue);
		seriesDocument.Save();
	}
}

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