I have a custom record where the form shall switch depending on the value of a field in the custom record.
I set this in page init client script and it works.
When I now change the value of the field on the form I want the form to change, so I have added the same to the fieldchange event. This also works but then the
nlapiSetFieldValue('customform', new_form)
obviously reloads the records with rejecting my changes.
The pageinit script gets the old value in the field driving the form change and changes everything back.
Any idea how I can prevent the reject of the value with the new page load? Do I need to do the changes at another event?
Coding:
function bs_line_pageinit(type) {
//alert ('pageinit: ' + type + ' ' + nlapiGetFieldValue('custrecord_ms_bz_type'));
// set form
set_form();
}
function bs_line_fieldchange(type, name) {
switch(name) {
case 'custrecord_ms_bz_type':
//alert ('fieldchange: ' + nlapiGetFieldValue('custrecord_ms_bz_type'));
set_form();
default:
}
}
function set_form() {
// set form
var trtype = nlapiGetFieldValue('custrecord_ms_bz_type');
var new_form = nlapiGetFieldValue('customform');
switch(trtype) {
case '1':
new_form = 83;
break;
case '4':
new_form = 82;
break;
case '5':
new_form = 85;
break;
case '6':
case '9':
new_form = 84;
break;
case '7':
new_form = 81;
break;
default:
}
if (nlapiGetFieldValue('customform') != new_form) {
nlapiSetFieldValue('customform', new_form);
}
}