Clear field value based on auto populated field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-30-2023 02:09 AM
Hi All,
-> I have 2 reference fields on incident form "incident manager" and "Managing Group". If incident manager is selected, the respective group should be populated on Managing Group field that the incident manager is a part of.
-> After Managing Group has auto populated, if anyone manually changed that group, then I need to make the "incident manager" field as empty.
-> For auto populating Managing group based on incident manager, I have written on change client script & Display BR, That is working fine.
-> But to clear field value based on manual change of Managing group. I have written, on change client script, but it is conflicting. it is always clearing the field value. can anyone please suggest.
Display BR
(function executeRule(current, previous /*null when async*/ ) {
var MI_manager = current.u_incident_manager;
g_scratchpad.grp = 'false';
var x = gs.getProperty('MI_Groups');
var grpList = x.split(',');
for (var i = 0; i < grpList.length; i++) {
if (gs.getUser().getUserByID(MI_manager).isMemberOf(grpList[i].trim())) {
g_scratchpad.grp = 'true';
}
}
})(current, previous);
Onchange CS to populate group
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var grp = g_scratchpad.grp;
if(grp){
g_form.setValue('u_managing_group',grp);
}
}
Onchange CS to clear field value if group manually changes
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
g_form.clearValue('u_incident_manager');
}
Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-30-2023 02:24 AM
@Saranya2 try below
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
if(newValue != oldValue){
g_form.clearValue('u_incident_manager');
}
}
Best regards
Suyog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-30-2023 03:05 AM
Hi @Suyog Aptikar ,
I have tried your code, it is always clearing the incident manager field value because group value is changing based on manager. So always it will match the condition old value != new value.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-30-2023 03:16 AM - edited ‎10-30-2023 03:16 AM
you can combine what @Anil Lande had provided in my script as below:
if(newValue != oldValue && newValue=='')
Best regards
Suyog

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-30-2023 02:27 AM
Hi,
You need make change on 2nd client script as below:
Onchange CS to clear field value if group manually changes
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading ) {
return;
}
if(newValue===''){
g_form.clearValue('u_incident_manager');
}
}
Thanks
Anil Lande