Implementing Custom Java Function with Save Record Activity to Create 'N' number of records in unrelated repository with single workflow
book
Article ID: KB0072589
calendar_today
Updated On:
Description
Consider we have two repositories product and price as separate(No relationship between them) in an enterprise.
Example scenario: As a part of workflow, the product record gets configured in the product repository with its other relationships. As a part of the same workflow, price records should get created in the price repository. For a particular product there can be 'N' number of prices. To achieve the above requirement we have implemented a custom Java function with Save Record Activity.
Issue/Introduction
Creating records in two repositories which are not related as a part of single workflow by using Save Record Activity and Custom Java function
Resolution
Below are the steps we have followed to implement the mentioned requirement.
1). Created CUSTOM Java Function that will take input as Starting character for the product ids that need to be created and a number of records that need to be created.
2). Find the snippet below for the RuleBase function and custom Java function.
<constraint>
<name>FetchArray</name>
<description>Generate Productids based on the input and counter</description>
<action>
<assign>
<var>arrayDerivedIDs</var>
<op func="returnIncrCount">
<const type="string">PRICEID_</const>
<const type="number">10</const>
</op>
</assign>
</action>
</constraint>
3). The above constraint will pass “PRICEID_” and number of price id to be created to our custom Java function.
private Object returnIncrCount(HashMap inArgs){
ArrayList retValue=new ArrayList();
ArrayList argList = null;
String defaultValue = "Y";
HashMap options = null;
Object arg1 = null;
Object arg2 = null;
long cntr;
String str1 = null;
int cnt=2;
try {
// get function arguments
if(inArgs.containsKey(IRulebase.FUNCTION_ARGUMENTS)){
argList = (ArrayList)inArgs.get(IRulebase.FUNCTION_ARGUMENTS);
System.out.println("got arglist successfully");
}else{
MqLog.log(this, MqLog.INFO, "No custom function arguments found");
}
arg1 = argList.get(0);
arg2 = argList.get(1);
cntr = (Long)arg2;
System.out.println("got str1 successfully --> "+cntr);
str1 = (String)arg1;
System.out.println("got str1 successfully -> "+str1);
for (int i=1;i<=cntr;i++)
{
retValue.add(str1+"_"+i);
}
return retValue;
// System.out.println("Returning for value:" + retValue);
//return(retValue);
//MqLog.log(this,MqLog.INFO,"returnAttributeValue: Number of arguments: " + argList.size());
} catch (Exception ex) {
System.out.println("EXCEPTION IN CUSTOM FUNCTION BEGIN ");
System.out.println(ex);
ex.printStackTrace();
System.out.println("EXCEPTION IN CUSTOM FUNCTION END ");
}
return (null);
}
}
4), Compile this Java code by adding “AllECMClasses.jar, ECMClasses.jar and Log4j.x.jar “ in the Classpath parameter.
5). Modify / Customize out of box workflow to call this Rulebase in the workflow. Updated out of the box by including the following three activities.
<Transition FromActivity="CheckRecordState" ToActivity="EvaluateRulebase_GenerateIDS"/>
<Transition FromActivity="EvaluateRulebase_GenerateIDS" ToActivity="SaveGeneratedIDS"/>
<Transition FromActivity="SaveGeneratedIDS" ToActivity="UpdateStatusOfNewlyCreatedRecords"/>
<Transition FromActivity="UpdateStatusOfNewlyCreatedRecords" ToActivity="SetStatusToSuccess"/>
<Activity Name="EvaluateRulebase_GenerateIDS">
<Action>EvaluateRuleBase</Action>
<Description lang="en">Apply Validation rules for Computing Related VPD Records Repository</Description>
<Parameter direction="in" type="string" eval="constant" name="eventState">EVALUATERULEBASE</Parameter>
<Parameter direction="in" name="Rulebase" eval="constant" type="string">support/rulebase/catalogvalidation_CreateREPB.xml</Parameter>
<Parameter direction="in" name="EvaluateChildren" type="boolean" eval="constant">false</Parameter>
<Parameter direction="in" eval="constant" type="string" name="MasterCatalogName">REPB</Parameter>
<Parameter direction="in" name="InDocument" type="document" eval="variable">inDoc</Parameter>
<!--Parameter direction="in" name="InRecordList" type="recordlist" eval="variable">inRL</Parameter-->
<Parameter direction="in" name="Severity" type="long" eval="constant">9</Parameter>
<Parameter direction="in" name="RemoveRecord" type="string" eval="constant">FATAL</Parameter>
<Parameter direction="in" name="SaveFlag" type="string" eval="constant">SAVE</Parameter>
<Parameter direction="in" name="LogOption" type="string" eval="constant">F</Parameter>
<Parameter direction="out" name="ValidationErrors" type="long" eval="variable">fatalErrors</Parameter>
<Parameter direction="out" name="ValidationErrors1" type="long" eval="variable">warningErrors</Parameter>
<Parameter direction="out" name="arrayDerivedIDs" type="arraylist" eval="variable">arrayDerivedIDs</Parameter>
<Parameter direction="out" name="OutDocument" type="document" eval="variable">workDoc</Parameter>
</Activity>
<Activity Name="SaveGeneratedIDS">
<Action>SaveRecord</Action>
<Description lang="en">Save Related VPD Records</Description>
<Execution>SYNCHR</Execution>
<Parameter direction="in" name="MasterCatalog" type="string" eval="constant">REPB</Parameter>
<Parameter direction="in" name="InDocument" type="document" eval="variable">workDoc</Parameter>
<Parameter direction="in" name="Rulebase" type="string" eval="constant">support/rulebase/rbdummy.xml</Parameter>
<Parameter direction="in" name="GenerateExistenceError" type="string" eval="constant">False</Parameter>
<Parameter direction="in" name="VersionOption" type="string" eval="constant">LATEST</Parameter>
<Parameter direction="in" name="ProductIds" eval="variable" type="arraylist">arrayDerivedIDs</Parameter>
<!-- Parameter direction="in" name="ATTRIBUTE_LevelCode" type="arraylist" eval="variable">arrayDerivedVPDLevels</Parameter -->
<Parameter direction="in" name="Severity" type="long" eval="constant">9</Parameter>
<Parameter direction="in" name="AsynProcessIndicator" type="boolean" eval="constant">false</Parameter>
<Parameter direction="in" name="OverrideConflict" type="boolean" eval="constant">true</Parameter>
<Parameter direction="in" name="Overwrite" type="boolean" eval="constant">true</Parameter>
<Parameter direction="out" eval="variable" type="long" name="RecordsAttempted">RecordsAttempted</Parameter>
<Parameter direction="out" eval="variable" type="long" name="RecordsWithErrors">ErrorsFound</Parameter>
<Parameter direction="out" eval="variable" type="long" name="RecordsWithWarnings">WarningsFound</Parameter>
</Activity>
<Activity Name="UpdateStatusOfNewlyCreatedRecords">
<Action>UpdateRecordState</Action>
<Description lang="en">Set the record status as Confirmed - for VPD Records</Description>
<Parameter direction="in" type="string" eval="constant" name="eventState">UPDATERECORDSTATE</Parameter>
<Parameter direction="in" name="Status" type="string" eval="constant">CONFIRMED</Parameter>
<Parameter direction="in" name="MasterCatalog" type="string" eval="constant">REPB</Parameter>
<Parameter direction="in" name="InDocument" type="document" eval="variable">workDoc</Parameter>
<Parameter direction="out" eval="variable" type="long" name="StepID">update_step</Parameter>
<Parameter direction="out" name="CommandStatus" type="string" eval="variable">commandStatus</Parameter>
</Activity>
Attachments
Implementing Custom Java Function with Save Record Activity to Create 'N' number of records in unrelated repository with single workflow
get_app
Implementing Custom Java Function with Save Record Activity to Create 'N' number of records in unrelated repository with single workflow
get_app
Feedback
thumb_up
Yes
thumb_down
No