1 Reply Latest reply on Dec 15, 2020 2:56 AM by Stefan Reinhardt

    Create import function to delete Article Reference

    DTGroup Support New Member

      8.1.0.01.00

       

      Useful addition for importing article-article references: an import function that can delete article references

      I have managed to create a FieldPath to locate a reference from an article and setLogicalKeyValue on its EntityPath to get exactly the correct reference type to the correct article. Or no KeyValues and get all types of references to all articles from the selected article for logging purposes.

      FieldPath referencePath = repositoryService.getFieldPath(repositoryService.getFieldByIdentifier("ArticleReference.ReferencedSupplierAid"));

      referencePath.getEntityPath().setLogicalKeyValue("ArticleReferenceType.LK.ReferenceType", enumValue);

      referencePath.getEntityPath().setLogicalKeyValue("ArticleReferenceType.LK.ReferencedSupplierAid", ToArticle);

       

      Expression itemExpression = new EqualExpression(new FieldPathExpression(supplierAidPath),new ValueExpression(FromArticle));
      SearchParameters searchParameters = new SearchParameters(DataSource.MASTER  ,"ArticleType", itemExpression);

      EntityProxy[] structureProxies = searchService.searchAsEntityProxies(new NullProgressMonitor(), searchParameters, null);

       

      ArticleProxy articleProxy = new ArticleProxy(ArticleCoreConst.ENTITYID_ARTICLE, CatalogProxy.MASTER_CATALOG_PROXY, id);

      EntityProxy entityProxy = articleProxy;

      EntityDetailModel entityDetailModel = entityProxy.getDetailModel(LoadHint.EVERYTHING);

      entityDetailModel.acquireWrite(null);

      EDataObject[] objdt = entityDetailModel.getDataObjects(referencePath.getEntityPath());

      objdt[0].set("referenceType", 8);     // objdt[0].delete();

      entityDetailModel.save(null);

      entityDetailModel.releaseWrite();

      entityDetailModel.releaseRead();

       

      This will change the reference type. But the delete() will not work. Any ideas?

      Excerpt of code here but it seems to work, a) logging all refererences b) changing reference type
      But not c) actually deleting the reference