I am new to Hybris and I still do not know how impex works.
I would like to know how to make an impex script to update a description of a front tile component.
Thank you.
You can find here the syntax of the impex file :
https://help.hybris.com/6.3.0/hcd/1c8f5bebdc6e434782ff0cfdb0ca1847.html#loio1c8f5bebdc6e434782ff0cfdb0ca1847
Basically it's a csv file (semicolon-separated) with specific structure/header,
mode type[modifier=value];attribute[modifier=value];attribute[modifier=value];attribute[modifier=value]
mode : action to be executed -> INSERT, UPDATE, INSERT_UPDATE, REMOVE.
type : item to be processed -> Product, Category, Customer,...
attribute : the attribute of the item -> Product.name, category.description,...
modifier : additional information to process an attribute -> unique, lang, ...
Example :
Assuming we have the following Item type :
public class ProductModel {
private String code;
private String name;
}
The impex to import Products would be like :
INSERT Product ;code[unique=true] ; name[lang=en] ;name[lang=fr]
;123456; ; This a product name ;nom du produit
To answer your question specifically -> to Update the description of a front tile component, thte impex file should be something like :
INSERT_UPDATE Name_of_the_Component ;code[unique=true] ; description[lang=en]
;code of the component ; The description to update
Related
I'm trying to retrieve the option set values (localized labels and integer Ids) for a specific field on a specific entity. Below is the code that I am using, but every time I execute it, it brings back ALL optionsets that are currently in my system (about 800+) and I don't want to do that.
EntityDefinitions(LogicalName='#MY_ENTITY#')/Attributes/Microsoft.Dynamics.CRM.PicklistAttributeMetadata?$select=LogicalName&$filter=LogicalName eq '#MY_ENTITY_ATTRIBUTE#'&$expand=OptionSet
maybe this can help,
/api/data/v9.1/ENTITY(guid OR Filter)?$select=ATTRIBUTE1,ATTRIBUTE2
include header:
{
"Prefer": "odata.include-annotations=OData.Community.Display.V1.FormattedValue"
}
this gives us a response like this:
{
"ATTRIBUTE1#OData.Community.Display.V1.FormattedValue": "Person",
"ATTRIBUTE1": 1,
"ATTRIBUTE2#OData.Community.Display.V1.FormattedValue": "Company",
"ATTRIBUTE2": 2
}
I'm using the stringmap entity to retrieve the optionsets.
This represents the optionsets as a simple table on which you can filter in the query
For example by calling:
/stringmaps?$filter=(objecttypecode eq 'contacts')
you get only the optionsets which are use in the contact entity. You can also filter on attribute name, the option value (field value) or option id (field attributevalue).
What I want to achieve:
I want to set the value of two attributes, a1 and a2, to null for any product where a third attribute, a3, has a specific enum value.
What I have so far:
I have a flexquery which fetches a list of PKs for products which fulfill the requirement for a3. I now need to set the attributes of the products with those specific keys. The query is as follows:
SELECT {p.pk} FROM {Product AS p JOIN ProductOrigin AS o ON {o.pk} = {p.origin}} WHERE {o.code} = 'MARKETPLACE'
What I need help with:
I do not know how to combine the results of the flexquery with a typical impex operation. What I ideally want is to be able to simply pass the list of PKs to an INSERT_UPDATE as in:
INSERT_UPDATE Product; pk ; a1 ; a2 ;
queryResult; null; null;
I do not know if this is possible however. Even better would be if there is an even easier way to do this that I have not thought of.
Hi Erik you can achieve this even without using the Impex header and use groovy, steps are below.
Create groovy
#%impex.enableCodeExecution(true);
"#%groovy%
def queryCreditCardsToRemove = ''' SELECT {p.pk} FROM {Product AS p JOIN ProductOrigin AS o ON {o.pk} = {p.origin}} WHERE {o.code} = 'MARKETPLACE''''
def products = (Collection<ProductModel>)flexibleSearchService.search(queryCreditCardsToRemove).result
products.stream()
.each{
modelService
}
modelService.removeAll(cardsToRemove)
";
Save the file as impex
3.# Disable legacy scripting (makes groovy work at impex)
impex.legacy.scripting=false---> either you can change dynamically via hac-->configuration or add in local.properties
here is one beanshell script, execute it from hac -> console -> scripting languages!
In the below script, you need to put query that will give you result which is expected to you and on that result script will do further operations of saving null values to attributes!
import de.hybris.platform.servicelayer.search.FlexibleSearchService
import de.hybris.platform.servicelayer.search.SearchResult;
import de.hybris.platform.core.model.product.ProductModel
import de.hybris.platform.variants.model.VariantProductModel;
final Map<String, Object> params = new HashMap<String, Object>();
String query = "-------------- query to check condition of third (a3) attribute
with specific enum value ----------------------"
params = -----------if any need to be passed in query ------------------;
FlexibleSearchService fss = spring.getBean("flexibleSearchService")
final SearchResult<ProductModel> searchResult = fss.search(query, params);
for (final ProductModel product : searchResult.getResult()) {
// set attributes a1 and a2 to null
// save product model using modelService
}
I have a data structure as follows defined in my items.xml file:
An itemtype of Country type having a attribute(name as collection type of another itemtype Region,which has an attribute(name=locality)of another itemtype say Locality. What would be the right option for ImpEx import to insert some Localities and Countries?We were trying a script like :
INSERT_UPDATE Country;code;regions(locality(code))
;abc;1,2
Separate Country from Region from locality you would write something like :
INSERT_UPDATE Locality;code
;locality_1
;locality_2
;locality_3
INSERT_UPDATE Region;code;locality(code)
;1;locality_1
;2;locality_2
;3;locality_3
INSERT_UPDATE Country;code;regions(code)
;c_1;1,2,3
I don't know whether the below impex is correct for my requirement.please correct me if i am wrong.i want to assign categories to classification class.
$classificationSystem=hpeClassification
$classificationCatalogVersion=catalogversion(catalog(id[default=$classificationSystem]),version[default='1.0'])[unique=true,default=$classificationSystem:1.0]
$classificationClasses=Classificationclass(code[unique=true],name[lang=en],supercategories(code,$classificationCatalogVersion),$classificationCatalogVersion);
INSERT_UPDATE Product;code[unique=true];$classificationClasses;$catalogVersion;
;5476;/facets/care;
I think your missing some elements
First you need to define a classification catalog version macro:
$systemName=TelcoClassification;
$systemVersion=1.0;
INSERT_UPDATE ClassificationSystem; id[unique=true]; name[lang=en];
;$systemName;Telco ClassificationSystem;
$classCatalogVersion=catalogversion(catalog(id[default=$systemName]),version[default=$systemVersion])
Then you define the Classification class macro
$class=classificationClass(ClassificationClass.code,$classCatalogVersion)[unique=true]
You create the DB object :
INSERT_UPDATE ClassificationSystemversion; catalog(id)[unique=true] ; version[unique=true] ; active ; writeprincipals(uid); languages(isocode); inclPacking[virtual=true,default=true]; inclDuty[virtual=true,default=true]; inclFreight[virtual=true,default=true]; inclAssurance[virtual=true,default=true]
;$systemName ;$systemVersion ;true ;employeegroup;en;
INSERT_UPDATE ClassificationClass;$classCatalogVersion[unique=true];code[unique=true];allowedPrincipals(uid)[default='customergroup']
;;compatibilityclassification
You define the attribute for classification :
INSERT_UPDATE ClassificationAttribute;$classSystemVersion;code[unique=true]
;;featurecompatibility
$class=classificationClass(ClassificationClass.code,$classCatalogVersion)[unique=true]
$attribute=classificationAttribute(code,$classSystemVersion)[unique=true]
INSERT_UPDATE ClassificationAttributeValue;code[unique=true];$classSystemVersion
;feature_bt10
INSERT_UPDATE ClassAttributeAssignment;$class;$attribute;position;$unit;attributeType(code[default=string]);multiValued[default=false];range[default=false];localized[default=false];attributeValues(code,$classSystemVersion)
;compatibilityclassification;featurecompatibility;0;;enum;true;;;feature_bt10
And you link it to a product
$clAttrModifiers=system='TelcoClassification',version='1.0',translator=de.hybris.platform.catalog.jalo.classification.impex.ClassificationAttributeTranslator,lang=en
$feature1=#featurecompatibility[$clAttrModifiers];
UPDATE Product;code[unique=true];$feature1;$catalogversion
;109058;feature_bt10;
For category:
INSERT_UPDATE Category;code[unique=true];allowedPrincipals(uid)[default='customergroup'];$catalogversion
;devices
UPDATE Category; $catalogversion; code[unique=true]; supercategories(code,$classCatalogVersion)[mode=append]
;;devices;compatibilityclassification;
Old question, but here is the answer, for the product instead of assigning the attribute assign the category.
UPDATE Product;code[unique=true];supercategories(code)[mode = append];
; 5476; <code of your classification class>;
I need to customize the Expense Claim screen (EP301000) to do the following:
Add user field as a checkbox to header section (Done)
Use that checkbox value to filter the RefNbr PXSelector lookup to only show results for the Employee ID shown on the 'Claimed By' field.
Looking at the DAC for RefNbr, I don't see any normal PXSelector lookup that I'm used to seeing.
Is there a way to do this?
You can see the DACField is using an attribute [EPExpenceClaimSelector]
The definition of that is as below
public class EPExpenceClaimSelectorAttribute : PXSelectorAttribute
{
public EPExpenceClaimSelectorAttribute()
: base(typeof(Search2<EPExpenseClaim.refNbr,
InnerJoin<EPEmployee, On<EPEmployee.bAccountID, Equal<EPExpenseClaim.employeeID>>>,
Where<EPExpenseClaim.createdByID, Equal<Current<AccessInfo.userID>>,
Or<EPEmployee.userID, Equal<Current<AccessInfo.userID>>,
Or<EPEmployee.userID, OwnedUser<Current<AccessInfo.userID>>,
Or<EPExpenseClaim.noteID, Approver<Current<AccessInfo.userID>>,
Or<EPExpenseClaim.employeeID, WingmanUser<Current<AccessInfo.userID>>>>>>>, OrderBy<Desc<EPExpenseClaim.refNbr>>>)
, typeof(EPExpenseClaim.docDate)
, typeof(EPExpenseClaim.refNbr)
, typeof(EPExpenseClaim.status)
, typeof(EPExpenseClaim.docDesc)
, typeof(EPExpenseClaim.curyDocBal)
, typeof(EPExpenseClaim.curyID)
, typeof(EPEmployee.acctName)
, typeof(EPExpenseClaim.departmentID)
)
{
}
}
You can use the same approach to create an attribute of your own with additional condition and use it in your cache attached method to replace the default selector.