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

jarodm
Mega Guru

Which part isn't running? Not returning any records from the GlideRecord?



Have you run it as a Fix Script?



JarodM


joaosantos
Mega Expert

the function is not running. the gs.log() is not "printing"


I did not try fix scripts how do i run it on an ui action


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


This is what i have now, but still not working


find_real_file.png


function runFillPrevious(){


gsftSubmit(null, g_form.getFormElement(), 'fill_previous');


}




if(typeof window == 'undefined')


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();


  action.setRedirectURL(current);




}