Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Ui action doing server side code

joaosantos
Mega Expert

i have the following ui action that is not running

fillComponents2016();

function fillComponents2016(){

  var invoices = new GlideRecord('u_invoices');

  var total_ytd_fte = 0;

  var total_ytd_cre = 0;

  var total_ytd_tech = 0;

  var total_ytd_tps = 0;

  invoices.addQuery('u_service_agreement',current.sys_id);

  invoices.addEncodedQuery('u_invoice_date<javascript:gs.beginningOfThisYear()');

  invoices.query();

  gs.log('Number of lines: ' + invoices.getRowCount(),'10 april ui action');

  while(invoices.next()){

  total_ytd_fte = total_ytd_fte + (parseFloat(invoices.u_fte.getCurrencyValue()));

  total_ytd_cre = total_ytd_cre + (parseFloat(invoices.u_cre.getCurrencyValue()));

  total_ytd_tps = total_ytd_tps + (parseFloat(invoices.u_third_party_suppliers.getCurrencyValue()));

  total_ytd_tech = total_ytd_tech + (parseFloat(invoices.u_technology.getCurrencyValue()));

  }

  current.u_fte_previous_cost = total_ytd_fte;

  current.u_cre_previous_cost = total_ytd_cre;

  current.u_tps_previous_cost = total_ytd_tps;

  current.u_tech_previous_cost = total_ytd_tech;

  current.update();

}

1 ACCEPTED SOLUTION

Hi Joao,



Please check the link below to get some information about how to run server side script in ui action.



https://www.servicenowguru.com/system-ui/ui-actions-system-ui/client-server-code-ui-action/



and by the way in ui action there is a field "client" just checked that then you will see "onClick" if you mention any name for eg:


test();



then use this function in the script section and write your client side scripting .



and if you want to perform server side scripting then mention another function in script section. for eg: test2().




it would be like this.



test1()


{


alert('testing');


}



test2()


{


mention your glide query here and do some sever side code


}





Thanks,


Harshvardhan


View solution in original post

6 REPLIES 6

well im dumb.


one of the table names was incorrect


dvp
Mega Sage

As far as i know you should never combine addQuery with addEncodedQuery()



use either one not both