List Collector Options should remove when vendor name changes on Exception form

Priya madyapgol
Tera Contributor

Hello Team,

 

I have one question on Exception form Workspace view

 I have 2 fields ie, 1. Vendor Name (Reference field) referenced to user table 2. To(List Collector field)Vendor's email will autopopulate on This field.

Now when i select any Vendor's name at that time his Email is autopopulating on TO field which is correct, but when i chnage vendor name or i remove the vendor name TO field is not clearing it's value.

Please find the snapshots attached.

Priyamadyapgol_0-1756237594797.jpeg

 

Priyamadyapgol_1-1756237616436.jpeg

 

I need to show this on CSM/FSM workspace, can anybody please help me on this.

Thanks,

 

 

5 REPLIES 5

kaushal_snow
Mega Sage

Hi @Priya madyapgol ,

 

To ensure the List Collector resets when the Vendor Name changes, just add an onChange Client Script on the Vendor Name field like so:

 

function onChange(control, oldValue, newValue, isLoading) {
if (isLoading) return;
g_form.clearValue('to'); // Replace 'to' with your list collector's name
}


This will clear out any previously selected email addresses whenever the vendor field is updated, preventing confusion and ensuring data accuracy. For Service Portal or Workspace, make sure the script's UI Type is set to Both so it works everywhere consistently.

 

If you found my response helpful, please mark it as ‘Accept as Solution’ and ‘Helpful’. This helps other community members find the right answer more easily and supports the community.

 

 

Thanks and Regards,
Kaushal Kumar Jha - ServiceNow Consultant - Lets connect on Linkedin: https://www.linkedin.com/in/kaushalkrjha/

Hello @kaushal_snow ,

Thanks for your response.

But this is not working properly, for 2-3 seconds the field(u_to) is clearing the value, but again the old values are coming, could you please help me on this, how can i fix.

I have written the below Script include and Client script to Populate vendors mail id on the basis of Vendors name.

Priyamadyapgol_0-1756406744307.png

Priyamadyapgol_1-1756406779363.png

Thanks,

 

 

Hi @Priya madyapgol ,

 

Try below:

 

 

function onChange(control, oldValue, newValue, isLoading) {
  if (isLoading || !newValue) return;

  // Clear the 'u_to' List Collector field
  g_form.clearValue('u_to');
  
  // Optionally, fetch and set the vendor's email if a valid vendor is selected
  if (newValue) {
    var ga = new GlideAjax('getVendorEmail');
    ga.addParam('sysparm_name', 'getEmail');
    ga.addParam('vendor_id', newValue);
    ga.getXMLAnswer(function(response) {
      if (response) {
        g_form.setValue('u_to', response);
      }
    });
  }
}

 

 

 

Script include:

var getVendorEmail = Class.create();
getVendorEmail.prototype = Object.extendsObject(AbstractAjaxProcessor, {
  getEmail: function() {
    var vendorId = this.getParameter('vendor_id');
    var vendor = new GlideRecord('sys_user');
    if (vendor.get(vendorId)) {
      return vendor.email;
    }
    return '';
  }
});

 

 

 

If you found my response helpful, please mark it as ‘Accept as Solution’ and ‘Helpful’. This helps other community members find the right answer more easily and supports the community.

 

 

 

Thanks and Regards,
Kaushal Kumar Jha - ServiceNow Consultant - Lets connect on Linkedin: https://www.linkedin.com/in/kaushalkrjha/

Ravi Gaurav
Giga Sage
Giga Sage

Hi @Priya madyapgol 
You have two fields:

  1. Vendor Name → Reference field (pointing to sys_user table).

  2. To → List Collector field (autopopulates vendor’s email from selected Vendor).

  3. When you select a vendor, the email correctly auto-populates in To.

  4. But when you change vendor or clear vendor name, the To field is not getting cleared 

The current client script (or onChange logic) only handles adding email when vendor is selected, but it doesn’t handle clearing or replacing email when vendor is cleared/changed.

 

You need to extend your onChange Client Script on Vendor Name field:

function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue === oldValue) {
return;
}

// Clear the "To" field first
g_form.clearValue('to');

// If Vendor is empty, stop here
if (!newValue) {
return;
}

// Get the selected Vendor’s email
var gr = new GlideRecord('sys_user');
if (gr.get(newValue)) {
var email = gr.email;

if (email) {
// Set it in the To field
g_form.setValue('to', email);
}
}
}

 

--------------------------------------------------------------------------------------------------------------------------


If you found my response helpful, I would greatly appreciate it if you could mark it as "Accepted Solution" and "Helpful."
Your support not only benefits the community but also encourages me to continue assisting. Thank you so much!

Thanks and Regards
Ravi Gaurav | ServiceNow MVP 2025,2024 | ServiceNow Practice Lead | Solution Architect
CGI
M.Tech in Data Science & AI

 YouTube: https://www.youtube.com/@learnservicenowwithravi
 LinkedIn: https://www.linkedin.com/in/ravi-gaurav-a67542aa/