pass value from variable to UI macro

Pastupe
Mega Guru

Hello, I dont know how to set variable value to UI macro.

I have UI macro below and onchange client script

Onchange client script is able to alert me with variable, but I doesnt need alert, need to set this value to UI macro on form. So when user select value in field A, html data should be populated to field B ( field B is UI macro )

How can I do it ? Should I better create some UI page and pass data through ?

Actually I will need to pass html value to UI macro field through onchange wizard script.

thank you

/Petr

UI macro

<?xml version="1.0" encoding="utf-8" ?>

<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">

<html>

<head>

<script>

function checkDetails()

{

  var selected_training = g_form.getReference('u_select_training');

  var u_selected_training_description = selected_training.short_description;

alert('from date :'+u_selected_training_description);

}

</script>

</head>

</html>

</j:jelly>

Wizard Client Script

function onChange(control, oldValue, newValue, isLoading) {

if (!isLoading){

checkDetails();

}

}

1 ACCEPTED SOLUTION

adiddigi
Tera Guru

If I understand it right, it's fairly easy.



This is what I understood so far:



- You want to set a HTML field on the UI Macro with the Short_Description of the select training field on the form.


- One thing that's missing is the HTML of the field in the UI Macro.



Here is very small snippet I have set up:



My UI Macro has a field called "short description" which is an input, which I will be setting on Change of a field on the form. Here is the UI Macro. Notice the Script that's inside the UI Macro:




<?xml version="1.0" encoding="utf-8" ?>


<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">


Short Description: <input id="short_description" type="text"/>





  <script>


  function setDesc(text){


  $j("#short_description").val(text);


  }



  </script>


</j:jelly>





Now, the easy part : write an onChange script to call the setDesc. Because `setDesc` is loaded on the global name space you should be able to call it like this:




function onChange(control, oldValue, newValue, isLoading) {


    if (isLoading || newValue == '') {


          return;


    }


  setDesc(newValue);





    //Type appropriate comment here, and begin script below


   


}




Does that help?


View solution in original post

19 REPLIES 19

manikorada
ServiceNow Employee
ServiceNow Employee

Peter,



Its better to have two seperate UI macros and depending upon what value is selected, you can show/hide the macros as needed


adiddigi
Tera Guru

If I understand it right, it's fairly easy.



This is what I understood so far:



- You want to set a HTML field on the UI Macro with the Short_Description of the select training field on the form.


- One thing that's missing is the HTML of the field in the UI Macro.



Here is very small snippet I have set up:



My UI Macro has a field called "short description" which is an input, which I will be setting on Change of a field on the form. Here is the UI Macro. Notice the Script that's inside the UI Macro:




<?xml version="1.0" encoding="utf-8" ?>


<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">


Short Description: <input id="short_description" type="text"/>





  <script>


  function setDesc(text){


  $j("#short_description").val(text);


  }



  </script>


</j:jelly>





Now, the easy part : write an onChange script to call the setDesc. Because `setDesc` is loaded on the global name space you should be able to call it like this:




function onChange(control, oldValue, newValue, isLoading) {


    if (isLoading || newValue == '') {


          return;


    }


  setDesc(newValue);





    //Type appropriate comment here, and begin script below


   


}




Does that help?


Hello,


below is an image, sorry that I added it lately.


If you select item in Reference field below, in the macro under reference field data should be displayed from this reference field in UI macro -- like you select something through reference field   and html content from reference table is displayed in UI macro.



is this duable please ? Should I still consider to elaborate with your code above ?



Thank you


/Petr


1a.jpg


The solution provided by abhiram should work for you. You could also change the type of input field to something else and if we look at the image you provided , you could use a div with id .