I created a function to read the status of an Account's Related List items, and then add a Tag to the Account's pre-existing Tags based on those statuses. When those items' statuses go to status terminated, I need the Account's tag to go away, as well. I can get it to remove the tag as long as there is still one "other" tag left on the Account. However, when that is the only tag left on the Account, I cannot get it to remove that last remaining tag and just have NO TAGS on the Account. I've tried taglist.clear, taglist.delete, taglist.remove, taglist.removeAll, taglist.removeElement, and at least 50 other variations. Help, please!
gettags2 = List();
acctinfo = zoho.crm.getRecordById("Accounts",accountid);
gettags = acctinfo.get("Tag");
info gettags;
for each tag in gettags
{
tagname = tag.get("name");
info tagname;
tagid = tag.get("id");
info tagid;
if(tagname == "QIO" || tagname == "SNF.Paid" || tagname == "HS.ACO" || tagname == "PAYERS" || tagname == "State.Program")
{
info "GO AWAY";
}
else
{
gettags2.add({"name":tagname});
info gettags2;
}
}
emptytags = gettags2.isEmpty();
info emptytags;
if(emptytags == true)
{
gettags.clear();
info gettags;
tagmap = Map();
tagmap.put("Tag",gettags);
updatewithtag = zoho.crm.updateRecord("Accounts",accountid,tagmap);
info "UPDATED";
}
else if(emptytags == false)
{
tagmap2 = Map();
tagmap2.put("Tag",gettags2);
updatewithtag2 = zoho.crm.updateRecord("Accounts",accountid,tagmap2);
info updatewithtag2;
}