Onchange client script for when a field changes

GB14
Kilo Patron

Hello,

We have a requirement where a filed needs to change based on another field. 

If "Cost center" change then "EOC" should display the "list of codes" based on selected "Cost center"

I'm a novice at scripting. Any help would be greatly appreciated.

Thank you 🙂

1 ACCEPTED SOLUTION

GB14
Kilo Patron

Thanks everyone. We ended up getting help from the vendor and they were able to do the needful. 🙂

View solution in original post

12 REPLIES 12

Brad Bowman
Kilo Patron
Kilo Patron

What are the field or variable types of Cost center and EOC?  The complexity of your onChange script will depend on this.

We have these 2 fields. EOC should list codes based on selected Cost center

find_real_file.png

 

 

1 cost center have different codes 

 

find_real_file.png

Hi Gurbir,

 

Are both the fields Cost Center & EOC referencing same table or different.

Also, did you check comment from Mike something similar will have to be done as reference qulaifier is best fit for your business case.

Cost Center & EOC referencing the same table 

I tried like this but doesn't seem to be working:

 

find_real_file.png

Suggestions? 

TThanks

You can try something as below (sample script).

Create a Script include as below.

find_real_file.png

var getEOCCode = Class.create();
getEOCCode.prototype = Object.extendsObject(AbstractAjaxProcessor, {

    getEOC: function(costcenteris) {
		var finalis=[];
        var yis = new GlideRecord('yourtablename'); //replace correct table nae
        yis.addQuery('sys_id', costcenteris);
        yis.query();
        while (yis.next()) {
          finalis.push(yis.eoc.toString());//replace eoc with correct field name
        }
		return 'yis.eoc.sys_idIN'+finalis; //replace eoc with correct field name
    },

    type: 'getEOCCode'
});

 

Pass the reference qualifier on the EOC field as

javascript: new getEOCCode().getEOC(current.cost_center);

//replace cost_center with correct field from the form.