how to get the current record sys_id in UI macro's

ms_akila
Mega Expert

Want to get the current record sys_id in UI macros. that value should be passed to onclick function as 2nd parameter .Can anyone help me on this issue. i have tried $[current.sys_id] ..but it is not working

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

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

<j:set var="jvar_ref1" value="ref_image_macros_${ref}"/>    

<a id="${jvar_ref1}">

<img border="0" src="ref_record.pngx" width ="13" height="13" title="${gs.getMessage('Reference Record Info')}" onclick="displayRefRecord('${ref}');"/>  

</a>

<script>      

  function displayRefRecord(reference) {

//alert("kilk");

//alert("working"+reference);

  var fieldLabel = reference.split('.');

                var referenceField = fieldLabel[1];

  //alert("the label of the field--->"+referenceField);

//alert("sys_id-->"+g_form.getUniqueValue()+e);

  }      

</script>  

</j:jelly>

3 REPLIES 3

ms_akila
Mega Expert

I found out the solution...use g_form



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


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


<g:evaluate>


gs.log("current sys_id--->"+${current.sys_id});


</g:evaluate>


<j:set var="jvar_ref1" value="ref_image_macros_${ref}"/>    


<a id="${jvar_ref1}">


<img border="0" src="ref_record.pngx" width ="13" height="13" title="${gs.getMessage('Reference Record Info')}" onclick="displayRefRecord('${ref}');"/>  


</a>




<script>      


  function displayRefRecord(reference) {


alert("kilk");


//alert("working"+reference);


  var fieldLabel = reference.split('.');


                var referenceField = fieldLabel[1];



var v = g_form.getValue(referenceField);


alert("vvvvvv------>"+ v);


var u =g_form.getUniqueValue();


alert("uuuuuuuu-->"+u);




 


 


  }      


</script>  


</j:jelly>


Ankur Bawiskar
Tera Patron
Tera Patron

Hi Akila,



Is your script working and fetching the correct sys_id?



Regards


Ankur


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

yes Ankur,



g_form.getValue(referenceField) is retrieving the sys_id of the reference field record


g_form.getUniqueValue() is retrieving the sys_id of the incident where the reference field is presented.




mark correct if it is useful:)