Sufficiency Check Action Context Bind
The Sufficiency Check Action Context bind exposes methods to capture nodes, recipient mails, and channel ID data from the PDX Export Wizard for use in a business action. For more information, refer to the Publishing Only Sufficient Products to PDX topic in the Web User Interfaces documentation here.
Important: Testing this bind with the Test JavaScript button in the Edit Operation dialog results in error status. The error details include the text 'Cannot deliver bind of type SufficiencyCheckActionContext in this context.' Instead, run this business rule from code or within the UI.
The bind can be found within the 'Binds to' dropdown as shown below.
Configuration
To use any bind:
-
Create a business rule as defined in the Creating a Business Rule, Function, or Library topic.
-
Edit the business rule as defined in the Editing a Business Rule or Function topic.
-
In the Edit Operation dialog, add the bind to a business rule, as defined in the Adding a Bind topic in the Resource Materials online help documentation.
-
In the Edit Operation dialog, optionally add Messages, as defined in the Localized Messages for JavaScript Business Rules topic.
-
In the Edit Operation dialog, add JavaScript to call the bind.
JavaScript Methods
The bind exposes the following methods:
String getChannelID(); List<String> getRecipientMails(); List<Node> getNodes();
Example
The following is an example JavaScript that uses this bind.
Important: Example scripts should not be used as-is without thorough testing, including updating the script to match object and link types that exist on your system. JavaScript variable names are case-sensitive.
When insufficientProductInCollectionAction and sufficientProductInCollectionAction actions are called, relevant arguments are passed to the context. The JavaScript example (shown in the image above
logger.info("########################################### INSUFFICIENT Business Action ##############################");
//Sufficiency Check Action Context exposed methods:
var nodes = context.getNodes();
var recipientMails = context.getRecipientMails();
var channelID = context.getChannelID();
logger.info("Insufficient nodes: " + nodes.size());
logger.info("ChannelID: " + channelID);
logger.info("Recipient mails: "+recipientMails);
if(nodes.size() == 0) {
logger.info("########################################### INSUFFICIENT Business Action STOPPED ##############################");
return;
}
var linkTypeHome = manager.getHome(com.stibo.core.domain.classificationproductlinktype.ClassificationProductLinkTypeHome);
var linkType = linkTypeHome.getLinkTypeByID("Default Classification Product Link Type");
logger.info("#### Creating contentOrderClassification...");
var contentOrderClassification = topClassification.createClassification(java.time.LocalDateTime.now(), "Classification 1 user-type root");
logger.info("#### Retrieving attributes...");
var channelIDAttr = manager.getAttributeHome().getAttributeByID("channelID");
logger.info("#### Setting values on classification...");
contentOrderClassification.setSimpleValue(channelIDAttr, channelID);
var recipientMails = context.getRecipientMails();
try {
var recipientMailsValue = contentOrderClassification.getValue("recipientMails");
for(i=0; i<recipientMails.size(); i++) {
recipientMailsValue.addValue(recipientMails.get(i));
}
} catch (e) {
logger.info("Error: " + e);
}
logger.info("#### Adding nodes to classification...");
for(i=0; i<nodes.size(); i++) {
contentOrderClassification.createClassificationProductLink(nodes.get(i), linkType);
}
logger.info("########################################### INSUFFICIENT Business Action FINISHED ##############################");