How do I use onChange in snRecordPicker Directive

thomaskvistjaco
Kilo Expert

I have defined a funtion in the client controller, but when the field updates, the console logs an error stating that the function cannot be found:

Uncaught ReferenceError: getFields is not defined

      at HTMLInputElement.onchange (sp?id=sc_cat_item_guide&sys_id=8c9ef09…:1)

      at Object.trigger (js_includes_sp.jsx?v=10-25-2016_1048&lp=Thu_Feb_16_06_54_24_PST_2017&c=5_132:2850)

      at HTMLInputElement.<anonymous> (js_includes_sp.jsx?v=10-25-2016_1048&lp=Thu_Feb_16_06_54_24_PST_2017&c=5_132:3243)

      at Function.each (js_includes_sp.jsx?v=10-25-2016_1048&lp=Thu_Feb_16_06_54_24_PST_2017&c=5_132:215)

      at jQuery.fn.init.each (js_includes_sp.jsx?v=10-25-2016_1048&lp=Thu_Feb_16_06_54_24_PST_2017&c=5_132:59)

      at jQuery.fn.init.trigger (js_includes_sp.jsx?v=10-25-2016_1048&lp=Thu_Feb_16_06_54_24_PST_2017&c=5_132:3242)

      at constructor.triggerChange (js_includes_sp.jsx?v=10-25-2016_1048&lp=Thu_Feb_16_06_54_24_PST_2017&c=5_132:51550)

      at constructor.onSelect (js_includes_sp.jsx?v=10-25-2016_1048&lp=Thu_Feb_16_06_54_24_PST_2017&c=5_132:52463)

      at constructor.selectHighlighted (js_includes_sp.jsx?v=10-25-2016_1048&lp=Thu_Feb_16_06_54_24_PST_2017&c=5_132:52032)

      at constructor.<anonymous> (js_includes_sp.jsx?v=10-25-2016_1048&lp=Thu_Feb_16_06_54_24_PST_2017&c=5_132:51286)

HTML:

<sn-record-picker onChange="getFields(columnObj)" field="columnObj.value" table="columnObj.table"

        display-field="columnObj.displayField" display-fields="'u_nummer'" value-field="columnObj.valueField"

        search-fields="columnObj.searchFields" default-query="columnObj.query" page-size="100" >

</sn-record-picker>

Client script:

$scope.getFields = function (cObj) {

  console.log(cObj);

  }

Can anyone provide me with at working example on using OnChange?

Thanks.

/Thomas

1 ACCEPTED SOLUTION

thomaskvistjaco
Kilo Expert

Found the error:


The correct attribute name is on-change - not onChange. Duh!


Using that, it works.



Sorry for disturbing.



Regards,


Thomas


View solution in original post

3 REPLIES 3

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Thomas,



Could you explain what is the exact requirement you are trying to achieve?



Regards


Ankur


Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi,


Thanks for asking.


In this specific example, I would like to store the additional field values from the display-fields parameter in addition to the value specified by the field parameter.


columnObj is an iterator over the individual columns in a table row.


Generally speaking I was wondering if there is a way to get more than one value back, i.e. the whole record.



Regards


Thomas


thomaskvistjaco
Kilo Expert

Found the error:


The correct attribute name is on-change - not onChange. Duh!


Using that, it works.



Sorry for disturbing.



Regards,


Thomas