- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-28-2024 11:13 PM
Hi, I was learning about UI macros and my requirement is to add Assign me icon in front of caller field so that whenever user clicks on that icon, he can assign himself as caller. I have created following UI macro and added it to the dictionary level on caller field.
After adding this I was not able to see that macro on caller field in new form. Kindly help me with the functionality.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-04-2024 01:35 PM
I have found the solution. Above scripts were missing the main functionality. The exact solution should be that whenever the UI macro is clicked it should call a function which should contain the parameter as the field name. With the below code I was able to perform the functionality.
<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
<span id="add_me_button" class="btn btn-default icon-user-add" tabindex="0" title="Add me" onclick="addMe('caller_id')">
<span class="sr-only">Add me</span>
</span>
<script>
function addMe(reference) {
var userID = g_user.userID;
g_form.setValue(reference, userID);
}
</script>
</j:jelly>
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-28-2024 11:48 PM
Try this code in your 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">
<span id="${jvar_n}" class="btn btn-default icon-user-add" tabindex="0" title="Add me">
<span class="sr-only">Add me</span>
</span><script>
function addMe(reference) {
//Get the user reference field and populate the current user
var s = reference.split('.');
var referenceField = s[1];
g_form.setValue(referenceField, '$[gs.getUserID()]');
}
</script>
</j:jelly>
Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for
Kind Regards,
Rohila V
2022-25 ServiceNow Community MVP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-29-2024 11:43 AM - edited ‎07-29-2024 11:44 AM
Thank you for your solution!
this macro is not at all visible if I am keeping both the macros on this field
And if I remove the out of box one and keep the custom one then also it is not working and not adding me in caller field.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-30-2024 12:58 AM
Can you please share updated code?
You can use below code, I tested in my pdi and it's working as expected
<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
<span id="${jvar_n}" class="btn btn-default icon-user-add" tabindex="0" title="Add me">
<span class="sr-only">Add me</span>
</span><script>
function addMe(reference) {
//Get the user reference field and populate the current user
var s = reference.split('.');
var referenceField = s[1];
g_form.setValue(referenceField, '$[gs.getUserID()]');
}
</script>
</j:jelly>
Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for
Kind Regards,
Rohila V
2022-25 ServiceNow Community MVP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-30-2024 02:14 AM
Thank you for the solution!
With the above changes I can see all the ui macros all together. Previously I used , instead of ; in the syntax of ref_contributions in attribute section due to which it was not working . However with the above code I am still not able to add currently logged in user in the caller field (i.e. System administrator in pdi)
It is basically adding nothing in the field.
UI macro-
code
<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
<span id="${jvar_n}" class="btn btn-default icon-user-add" tabindex="0" title="Add me">
<span class="sr-only">Add me</span>
</span><script>
function addMe(reference) {
//Get the user reference field and populate the current user
var s = reference.split('.');
var referenceField = s[1];
g_form.setValue(referenceField, '$[gs.getUserID()]');
}
</script>
</j:jelly>