cancel
Showing results for 
Search instead for 
Did you mean: 

APIs for Taxonomy

Former Member
0 Kudos

MDMers,

Are there any APIs to create Taxonomy? Or only way to create taxonomy is through Import or create it manually in Data Manager?

Any ideas,

Subhash

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hello Subhash,

You can create taxonomy using APIs.

Please have a look at following blog.

Also,

Create taxonomy record the same way you create any other heirarchy record - with CreateRecordCommand. Then use CreateAttributeCommand for creating new taxonomy attributes (if need). Then bind attributes to newly created taxonomy record using CreateAttributeLinkCommand.

Use DeleteAttributeCommand/DeleteAttributeLinkCommand or ModifyAttributeCommand/ModifyAttributeLink commands for deleting or modifying taxonomy attributes and its' bindings to taxonomy records.

Taxonomy records itself can be modified like any other records - with ModifyRecordCommand.

About working with taxonomy lookups:

1. when loading records of main table make sure that FieldId of your taxonomy field is in the list of select fields of ResultDefinition and not forget to call setLoadAttributes(true) on it. Therefore taxonomy record and it's attribute values will be loaded together with record

2. use containsAttribute, getAttributeValue, setAttributeValue and others methods of Record interface for manipulating values of taxonomy attributes for a record

3. save changes of taxonomy attributes for a record using ModifyRecordCommand on this record

For exposing hierarchy in WD view you need to use node with recursive children in the context and Tree/TreeNodeType UI elements in view layout.

For load hierarchy records you have to use RetrieveLimitedHierTreeCommand. You can load whole hierarchy (as I know, SP05 API have a bug - only first 1000 record can be loaded) or load hierarchy nodes on demand (using OnLoadChildren action of TreeNodeType element).

Refer to this example of loading child records:

// Context structure:

// Tree (model node, model class built from com.sap.mdm.data.Record interface)

// |-- Children (recursive child node repeating Tree node)

// |-- DisplayValue (string value attribute, TreeNodeType's text property bound here)

// |-- HasChildren (boolean value attribute, TreeNodeType's hasChildren property bound here)

// parentElem is element of node Tree or Children for which we must load child records, null for first level of hierarchy

private void fillNodeWithChildren(IPrivateHierarchySelectView.ITreeElement parentElem) {

// Determining RecordId of parent record and context node to which child records belong

RecordId parentRecordId = null;

if (parentElem != null) parentRecordId = parentElem.modelObject().getId();

IPrivateHierarchySelectView.ITreeNode parentNode =

parentElem == null

? wdContext.nodeTree()

: parentElem.nodeChildren();

// Loading children with RetrieveLimitedHierTreeCommand

try {

RetrieveLimitedHierTreeCommand retTreeCmd = new RetrieveLimitedHierTreeCommand(...); // use suitable constructor

if (parentRecordId != null) retTreeCmd.setRootNode(parentRecordId);

retTreeCmd.setResultDefinition(...); // don't forget set ResultDefinition

retTreeCmd.execute();

HierNode subRoot = retTreeCmd.getTree()

parentNode.invalidate();

// Processing loaded child records - add elements into parentNode

if (subRoot == null) return;

IPrivateHierarchySelectView.ITreeElement childElem;

HierNode childRecord;

HierNode[] children = subRoot.getChildren();

int count = children == null ? 0 : children.length;

for (int i = 0; i < count; i++) {

childRecord = children<i>;

childElem = parentNode.createTreeElement(childRecord);

childElem.setDisplayValue(childRecord.getDisplayValue());

childElem.setHasChildren(!childRecord.isLeaf());

parentNode.addElement(childElem);

}

if (parentElem != null) parentElem.setHasChildren(count > 0);

} catch (/* Some MDM Exceptions */) {}

}

Don't forget call fillNodeWithChildren(null) in wdDoInit for load first level of hierarchy.

Thanks,

Shai

Answers (1)

Answers (1)

former_member208981
Contributor
0 Kudos

Hi Subhash,

Yes you can use API for Taxonomy.

Please use the below:

AddAttribute and LinkAttribute methods of the CatalogData class .

AddAttribute allows you to create attributes

LinkAttribute links an attribute to a category.

To create categories of course, you use the AddRecord method of the CatalogData class.

The AddRecord method has the following parameters

table - the table where records are to be added.

fields - list of field name/value pairs.

parentID - (if hierarchical table) the parent record/node ID.

position - (if hierarchial table) the position among siblings (zero-based).

and it returns the record id of the record just created.

Call it to create the root node and keep the record id.

Call it again and pass the record id of the root node and pass it as the parentID. Repeat until the whole hierarchy is created.

Hope it helps.

Thanks,

Priti.