Groovy Script to fetch available Gift Cards in SAP Hybris:
In this article, we are going to see how to fetch available Gift Cards in Hybris.
Groovy script to fetch available Gift Cards in Hybris:
import de.hybris.platform.servicelayer.search.SearchResult;
import com.core.model.GiftCardModel;
import org.apache.commons.collections4.CollectionUtils;
import java.lang.*;
import java.util.Collections;
// Flexible Search Query
fQuery = "Select {PK} from {GiftCard as g JOIN GiftCardType as type on {g.type}={type.pk}} where {type.code} = 'CSR'"; // we can mention any type of the Gift card in where clause.
// Initiate necessary services
flexibleSearchService = spring.getBean("flexibleSearchService");
final SearchResult<GiftCardModel> searchResult = flexibleSearchService.search(fQuery);
List<GiftCardModel> giftCards = CollectionUtils.isNotEmpty(searchResult.getResult()) ? searchResult.getResult() : Collections.emptyList();
println 'No. of Gift Cards found: ' + giftCards.size();
for (GiftCardModel giftCard : giftCards) {
println giftCard.getCode() + ' ' + giftCard.getBalanceAmount() + ' ' + giftCard.getCustomerEmailID();
}
println 'Script executed successfully!!!'
Sample Output:
xxxxxxxxxxxxxx01 1000 dummy@gmail.com
xxxxxxxxxxxxxx02 1000 dummy@gmail.com
xxxxxxxxxxxxxx03 1000 dummy@gmail.com
xxxxxxxxxxxxxx04 1000 dummy@gmail.com
xxxxxxxxxxxxxx05 1000 dummy@gmail.com
Comments
Post a Comment