- 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 01:22 AM
Hi Ramesh,
Since it is the same UI macro it would be difficult to know from where it got clicked
Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-24-2019 06:52 PM
Hi Ankur,
Thanks for your response, this code will identify from where UI macro is clicked
<?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>

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-24-2019 01:58 AM
Hi,
You have this UI Macro in front of each Field right as shown in image. Then you can hardcode it in your macro. Yes you need two different macro's for this.
One for CI and one for URL field. This will solve your issue.
Thanks,
Ashutosh Munot
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-24-2019 06:51 PM
Hi Ashutosh,
Thanks for your response, this code will identify from where UI macro is clicked
<?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>