As far as I know there is a lot of problem to change search criteria of dtlLookup or dtlHier dynamically, for that purposes I use dtlDropdown's which can be filled by preloaded values on-the-go.
Here is an example that should work in your scenario:
function statusReloadRC(value) {
var setRC = document.getElementsByName('SET.rootcause')[0];
setRC.options.length = 0;
setRC.options[0] = new Option("<Empty>", "", true, false);
var i=1;
if (value == "I") {
<PDM_LIST PREFIX=list WHERE="sym like 'INC.%' AND delete_flag = 0" FACTORY=rc>
setRC.options[i] = new Option("$list.sym", "$list.id", false, false);
i++;
</PDM_LIST>
} else if (value == "R") {
<PDM_LIST PREFIX=list WHERE="sym like 'SOL.%' AND delete_flag = 0" FACTORY=rc>
setRC.options[i] = new Option("$list.sym", "$list.id", false, false);
i++;
</PDM_LIST>
} else {
<PDM_LIST PREFIX=list WHERE="delete_flag = 0" FACTORY=rc>
setRC.options[i] = new Option("$list.sym", "$list.id", false, false);
i++;
</PDM_LIST>
}
}
<PDM_MACRO name=dtlDropdown hdr="Type" attr="zType2" evt="onChange=\\\"statusReloadRC(this.value)\\\"" lookup=no>
<PDM_MACRO name=dtlDropdown hdr="Rootcause" attr="rootcause" lookup=no>
I really don't like preSaveTrigger functionallity, because system shouldn't allow to input invalid values and that errors are really annoying because I'm sure that I filled everything correct. But if in your case you can't avoid it, code could be:
function zCompareRCandType() {
var rcInput = document.getElementsByName('KEY.rootcause')[0];
var typeInput = document.getElementsByName('SET.zType2')[0];
alert('Checking:\n\tType: ' + typeInput + '\n\tRootcause:' + rcInput);
if (typeInput == 'I') {
if (rcInput.indexOf('INC.') == -1)
return false;
} else if (typeInput == 'R') {
if (rcInput.indexOf('SOL.') == -1)
return false;
}
return true;
}
function preSaveTrigger() {
if (!zCompareRCandType()) {
alert('Please, select valid rootcause');
return false;
}
if ( _dtl.edit) {
If checking will be failed, could you provide meesage from alert in line 4?
PS: are we really talking about zType2 which is SREL to crt factory and rootcause which is SREL to rc factory?
Regards,
cdtj