Get Values from UI Page

praneeth24
Kilo Contributor

This is my UI Page.

var json = new Packages.org.json.JSONArray();

    while (jelly.jvar_diag.nextNode()) {

          var diagNode = jelly.jvar_diag.getNode();

          var jsonNode = new Packages.org.json.JSONObject();

          jsonNode.put("name", diagNode.name);

          var vals = new Packages.org.json.JSONArray();

          jsonNode.put("values", vals);

 

      addValueToJSON(vals, "Statistics For", diagNode.stats['instance_name']);

  addValueToJSON(vals, "Build Name", diagNode.stats['glide.build.name']);

  addValueToJSON(vals, "Build Date", diagNode.stats['glide.build.date']);

I need to get the value for Statics for and insert it in an another table.I am able to insert the record but the value is not coming as expected it is undefined.

Anyhelp would be appreciated

10 REPLIES 10

Chuck Tomasi
Tera Patron

Hi Praneeth,



I recommend you take a look at the Processing script field to process the output of your form.



You can set your text field inside a form tag and get it like a regular variable in the processing script.



<g:ui_form>


        <g:ui_choicelist name="myquantity" />


</g:ui_form>



Processing script:


gs.log('Quantity=' + myquantity');



UI Pages - ServiceNow Wiki


TechNow Episode List (episodes 1-3)


Hi Tomasi,



Actually i am having the values in   many variables.I have to send them to a field in the table and insert a record.Can you brief on that please


The concept is very much the same. Just process the variables based on the field names and do your GlideRecord insert in the processing script.



If you have form input fields named "first_name", "last_name", and "age". You could save that record like this in the processing script;



var rec = new GlideRecord('u_my_table'); // USE YOUR PROPER TABLE NAME HERE


rec.newRecord();


rec.u_first_name = first_name;


rec.u_last_name = last_name;


rec.u_age = age;


rec.insert();


Hi Tomasi,



This is my Page:


<g2:evaluate var="jvar_diagnostics" jelly="true">




  var x1 = [];


  var x2 = [];


  var x3 = [];


  var x4 = [];


  var x5 = [];


  var x6 = [];


  var x7 = [];


  var x8 = [];


  var x9 = [];


  var x10 = [];


  var x11 = [];


  var x12 = [];


  var x13 = [];





    function addValueToJSON(j, label, value, condition) {


          var val = new Packages.org.json.JSONObject();


          val.put("label", label);


          val.put("value", value);


          var flag = false;


          if (condition) {


                try {


                      s = '"' + value.replace(/\n/g, "").replace(/\"/g, "") + '"' + condition;


                      if (eval(s))


                            flag = true;


                } catch (ex) {


                }


          }


          val.put("flag", flag);


          j.put(val);


    }


   


    var json = new Packages.org.json.JSONArray();





  x1 = jelly.jvar_diag.emailReceivedCount, jelly.jvar_diag.conditions['emailsRecv'];


  gs.log('x1>>>>>Fury'+x1);


    addValueToJSON(json, "Emails (recv) last 60 minutes", jelly.jvar_diag.emailReceivedCount, jelly.jvar_diag.conditions['emailsRecv']);


    addValueToJSON(json, "Emails (sent) last 60 minutes", jelly.jvar_diag.emailSentCount, jelly.jvar_diag.conditions['emailsSent']);


    addValueToJSON(json, "Events pending", jelly.jvar_diag.eventCount, jelly.jvar_diag.conditions['events']);    


    addValueToJSON(json, "Log entries last 60 minutes", jelly.jvar_diag.logCount, jelly.jvar_diag.conditions['logEntries']);


    addValueToJSON(json, "POP3 Status", jelly.jvar_diag.pop3Status, jelly.jvar_diag.conditions['pop3Status']);


    addValueToJSON(json, "SMTP Status", jelly.jvar_diag.smtpStatus, jelly.jvar_diag.conditions['smtpStatus']);



    json.toString(3);



<script>



function onMyFunc(){


var grStatus = new GlideRecord("u_daily_checks");


grStatus.initialize();


grStatus.u_emails_sent_last_60_minutes = x1 ;


grStatus.insert();



}</script>




I am not getting the value inserted.Empty record with no field value is inserted









</g2:evaluate>