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

I'm still not fully understanding your setup.  Cost center is referencing which table?  EOC is referencing which table?  When a Cost center is selected, how does that effect which EOCs shold be available / how are EOC and Cost center connected/related?

Sudhanshu Talw1
Tera Guru

Okay after going through all screenshots,you can use the following script:

 

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

        getCodes:function(costCenterSysID){
            var result=new Array();
            var gr=new GlideRecord("<table_ref>");
            gr.addQuery("sys_id",costCenterSysID);
            gr.query();
            while(gr.next()){
                result.push(gr.getUniqueValue());
            }
            return "sys_id IN"+result;
        },
        type:'getEOCCode'
    }
 
Call this above script include in the reference qualifier of EOC field:
javascript: new getEOCCode.getCodes(current.cost_center);
 
Thanks 
Sudhanshu
 
 

GB14
Kilo Patron

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