- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-24-2019 12:38 AM
Hi All
I have created one Button in UI Macro and I used that in TWO different fields.
Now i just want to know when user is click on the button it should alert the field name from where they clicked
The below script i have used in 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">
<!-- <div class="contentcontainer med left" style="margin-left: 280px;"> -->
<button onclick="myFunction()">Click Here</button>
<script>
function myFunction(){
alert("Test")
}
</script>
</j:jelly>
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-24-2019 02:29 AM
Hi there,
Just tested with below, works fine! Look at the g_form.addErrorMessage('${ref}'.split('.')[1]); part. This gives the field_name you're decoration is on.
<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
<!-- <div class="contentcontainer med left" style="margin-left: 280px;"> -->
<button onclick="myFunction()">Click Here</button>
<script>
function myFunction(){
g_form.addErrorMessage('${ref}'.split('.')[1]);
}
</script>
</j:jelly>
If my answer helped you in any way, please then mark it as helpful.
Kind regards,
Mark
---
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-24-2019 02:29 AM
Hi there,
Just tested with below, works fine! Look at the g_form.addErrorMessage('${ref}'.split('.')[1]); part. This gives the field_name you're decoration is on.
<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
<!-- <div class="contentcontainer med left" style="margin-left: 280px;"> -->
<button onclick="myFunction()">Click Here</button>
<script>
function myFunction(){
g_form.addErrorMessage('${ref}'.split('.')[1]);
}
</script>
</j:jelly>
If my answer helped you in any way, please then mark it as helpful.
Kind regards,
Mark
---
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-24-2019 06:50 PM
Hi Mark
Thanks for your response. i got some idea from your code and i modified like below , now its working as i expexted
<?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_n" value="getCallContact_${ref}"/>
<a id="${jvar_n}" onclick="getCallContact('${ref}')" title="Get Caller's Contact No." class="icon-open-document-new-tab btn btn-default btn-ref"></a>
<!-- <i class="icon-search"></i> -->
<script>
function getCallContact(reference) {
var s = reference.split('.');
var referenceField = s[1];
alert(referenceField);
}
</script>
</j:jelly>