i have a handler that’s parsing thru a nested JSON request and saving records into 3 different models.
Campaign
Insertion
Insertion_Data
i thought of looping thru JSON for each Campaign, create the record, save it. create the child Insertion records, save all of them, create the child/grandchild insertion_data records, save all of them.
but it looks like nested transactions…don’t work as i imagine. i receive error:
An exception occurred when committing the transaction.The root cause of this exception was: java.lang.ClassCastException: coldfusion.runtime.TemplateProxy cannot be cast to java.lang.String. Code[BaseORMService line 1469]
i can comment out the save for Insertion and Insertion_Data and the campaign record saves just fine. but can’t get the insertion and insertion_data records to save.
`
Enter code here...
transaction {
for (var c=1;c<=ArrayLen(input.campaigns);c++) {
json_camp=input.campaigns[c];
param name=“json_camp.insertions” default="#[]#";
camp=campSvc.new();
campSvc.populate(target=camp, memento=json_camp);
campSvc.save(camp);
universal_id=camp.getuniversal_id();
for (var i=1;i<=ArrayLen(json_camp.insertions);i++) {
json_ins=input.campaigns[c].insertions[i];
ins=insSvc.new();
StructAppend(json_ins,ins_values);
insSvc.populate(target=ins,memento=json_ins);
//since we know the campaign universal_id, populate the insertions that belong to this campaign with that universal_id
ins.setuniversal_id(universal_id);
insSvc.save(ins);
insertion_id=ins.getInsertion_ID();
param name=“json_ins.insertion_element” default="#{}#";
json_ins_elem=json_ins.insertion_element;
for (ie in json_ins_elem) {
ins_elem=ins_ElemSvc.new();
insElem.setInsertion_ID(insertion_id);
insElem.setProduct_CD(ins.getProduct_CD());
insElem.setColumn_CD(ie);
insElem.setColumn_VALUE(json_ins.insertion_element[ie]);
insElem.setLast_MOD_TS(now);
insElem.setCreate_TS(now);
insSvc.save(insElem);
}
} // end loop thru json_camp.insertions
} // end loop thru input.campaigns
VARIABLES.response.addResult({
sf_oppt_id=camp.getsf_oppt_id(),
universal_id=camp.getuniversal_id()
});
//} //end transaction
`
`
`