Skip to Content
1
Former Member
Oct 07, 2014 at 12:52 PM

How to Save SavedValuesModel and SavedValueEntryModel using model service?. I want to track the changes in Last Changes Attribute on the Admin tab in HMC for product model attributes along with the classification attributes (Product Feature)

425 Views

I am using below code for this and not able to find the way to set the old value, new value and OldValueAttributeDescriptor for the savedValueEntryModel

Please provide help with the api code for storing the same and the code will work for all the attributes in the product model along with the classification attributes (product feature) in the product model.

final SavedValuesModel savedValuesModel = modelService.create(SavedValuesModel.class); final SavedValueEntryModel savedValueEntryModel = modelService.create(SavedValueEntryModel.class); savedValuesModel.setModificationType(SavedValueEntryType.CHANGED); savedValuesModel.setModifiedItem(product); savedValuesModel.setModifiedItemType(typeService.getComposedTypeForClass(ProductModel.class)); savedValuesModel.setModifiedItemDisplayString("Product '" + product.getCode() + "' (" + product.getPk().getLongValueAsString() + ")"); savedValuesModel.setUser(userService.getCurrentUser()); savedValuesModel.setTimestamp(new Date()); modelService.save(savedValuesModel);

     savedValueEntryModel.setParent(savedValuesModel);
     savedValueEntryModel.setModifiedAttribute(qualifier);
     savedValueEntryModel.setOldValueAttributeDescriptor(typeService.getAttributeDescriptor(ProductModel._TYPECODE, qualifier));
     savedValueEntryModel.setOldValue(originalValue);
     savedValueEntryModel.setNewValue(updatedValue);
     modelService.save(savedValueEntryModel);