Hi Michael,
Followed scenario might be illogical or partially offensive, but this is what I have, so, i'm sorry
I have table to keep list relations (LREL) that contains data from 4 different tables (nr/pcat/isscat/chgcat),
I'm validating data on list update,
for example I'm updating relation between nr and pcat,
then macro compare pcat with isscat and chgcat by sym.
After all procedures I receive new data row which contains my initial inputs: nr and pcat, and compared chgcat and isscat, if they were found.
But if I create new category (or make it active) and try to insert it in that relation, I'll receive data duplication.
This is why I check each inserting and merge data if it match existing data.
Here is simplier scenario where described method could be used:
- customer creates Request;
- system checks Customer, Category and Description (for example);
- if all data are matching already opened ticket:
- - system creates Activity Log about repetaed appeal;
- - system don't create new ticket but display to customer success message.
My current code part looks like:
if (!is_null(in_chg)) {
send_wait(0, top_object(), "call_attr", "chgcat", "val_by_key", "code", in_chg, 1, "persistent_id");
send_wait(0, top_object(), "call_attr", "chgcat", "dob_by_persid", 0, msg[1]);
new_chgcat = msg[0];
wc = format("nr IN (U'%s') AND (isscat.sym IN '%s' OR pcat.sym IN '%s')", nr, new_chgcat.sym, new_chgcat.sym);
logf(SIGNIFICANT, new_chgcat.sym);
send_wait(0, top_object(), "call_attr", "z_nr_cat", "sync_fetch", "STATIC", wc, -1, 0);
zcount = msg[1];
logf(SIGNIFICANT, "found: %d [%s]", zcount, wc);
if (zcount == 1) {
logf(SIGNIFICANT, "Merging data [%s]", new_chgcat);
send_wait(0, new_chgcat, "get_attr_vals", 1, "REL_ATTR");
macro::upd_val("z_nr_cat", wc, 3, 15, "chgcat", msg[3]);
break_op = 1;
} else if (zcount > 1) {
logf(ERROR, "Unable to merge [%d] items. Search string [%s].", zcount, new_chgcat.sym);
} else {
send_wait(0, top_object(), "call_attr", "isscat", "val_by_key", "sym", new_chgcat.sym, 1, "REL_ATTR");
if (msg_length() > 1) {
send_wait(0, this, "call_attr", "isscat", "set_val", msg[1], "SURE_SET");
}
send_wait(0, top_object(), "call_attr", "pcat", "val_by_key", "sym", new_chgcat.sym, 1, "REL_ATTR");
if (msg_length() > 1) {
send_wait(0, this, "call_attr", "pcat", "set_val", msg[1], "SURE_SET");
}
}
}
if (break_op) {
set_error(1);
set_return_data("Data merged successfuly!");
}
Best regards,
cdtj