SNX_CUSTOM_DYNAMIC_FLEX_FIELDS_EXPORTER

Description: Limited to code that handles the SNX export of dynamic flex fields. You can use a code extension of this type for any N4 entity that supports SNX export and Custom Dynamic flex fields.

Abstract Base Class: DefaultCustomDynamicFlexFieldsExporter

Interface: ECustomDynamicFlexFieldsExporter

Module: Inventory

Version Added: 2.2

Requires Code Extension Name or Name Pattern: Yes

Code Extension Name or Name Pattern: <Entity Name>SnxExporter

For example, if the code extension pertains to the entity UnitFacilityVisit, you would name the code extension UnitFacilityVisitSnxExporter.

Where to specify code extensions of this type: Any entity

System-Seeded Code Extensions Using this Type: None

 

Code example

The following code example addresses the SNX export of a dynamic flex field (unitCustomDFF_SNX_IMPORTER_TEST_FIELD) of the Unit entity from the UnitFacilityVisit entity.

import com.navis.argo.business.snx.DefaultCustomDynamicFlexFieldsExporter

import com.navis.framework.metafields.MetafieldId

import com.navis.framework.metafields.MetafieldIdFactory

import org.jdom.Element

import org.jdom.Namespace

 

class UnitFacilityVisitSnxExporter extends DefaultCustomDynamicFlexFieldsExporter {

  //override method to return the dynamic flex fields of the unit.

  public void getCustomDynamicMetafieldIds(Set<MetafieldId> inOutMetafieldIdSet) {

    Set<MetafieldId> dynamicMetafieldIds = getUnitCustomDynamicMetafieldIds();

    if (inOutMetafieldIdSet == null) {

      inOutMetafieldIdSet = dynamicMetafieldIds;

    } else {

      inOutMetafieldIdSet.addAll(dynamicMetafieldIds);

    }

  }

  //returns the set dynamicMetafieldIds of the Unit cynamic flex fields declared in _unitCustomFields list.

  private Set<MetafieldId> getUnitCustomDynamicMetafieldIds() {

    Set<MetafieldId> dynamicMetafieldIds = new HashSet();

    for (String field : _unitDynamicCustomFields) {

      dynamicMetafieldIds.add(MetafieldIdFactory.valueOf(field));

    }

    return dynamicMetafieldIds;

  }

  //override method which creates the custom-dynamic-flex-fields element for the Unit dynamic flex fields with each child element to containing the unit custom dynamic flex field name and value.

  public void createCustomDynamicFlexFieldsElement(Element inOutParentElement, Map inResultMap) {

    Namespace namespace = inOutParentElement.getNamespace();

    Element dynamicFieldsElement = new Element(DefaultCustomDynamicFlexFieldsExporter.CUSTOM_DYNAMIC_FLEX_FIELDS_ELEMENT, namespace);

    for (String field : _unitDynamicCustomFields) {

      MetafieldId fieldId = MetafieldIdFactory.valueOf(field);

      String value = (String) inResultMap.get(fieldId);

      if (value == null) {

        continue;

      }

      String customFieldId = "customFlexFields." + fieldId.fieldId;

      Element dynamicFieldElement = new Element(DefaultCustomDynamicFlexFieldsExporter.CUSTOM_DYNAMIC_FLEX_FIELD_ELEMENT, namespace);

      dynamicFieldElement.setAttribute(DefaultCustomDynamicFlexFieldsExporter.NAME_ATTRIBUTE, customFieldId, namespace);

      dynamicFieldElement.setAttribute(DefaultCustomDynamicFlexFieldsExporter.VALUE_ATTRIBUTE, translateToString(value), namespace);

      dynamicFieldsElement.addContent(dynamicFieldElement);

    }

    // if dynamicFieldsElement not empty attaching it to the parent element

    if (!dynamicFieldsElement.getContent().isEmpty()) {

      inOutParentElement.addContent(dynamicFieldsElement);

    }

  }

  //add the unit dynamic custom flex fields in this list to get fields through snx export.

  //if the field name is unitCustomDFFString1 then add the field as "ufvUnit.customFlexFields.unitCustomDFFString1"

  private List<String> _unitDynamicCustomFields = Arrays.          asList("ufvUnit.customFlexFields.unitCustomDFF_SNX_IMPORTER_TEST_FIELD");

}