Get the sys_id of the current record in UI macro

Michael Chaiwi2
Kilo Contributor

Hello,

I'm working on a custom UI macro to add attachment on a form. How can I get the sys_id of the current record and pass it to the second parameter of the saveAttachment function. The following code doesn't work and I'm not familiar with Jelly Script. Thank you so much for your help.

<?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="label-text" style ='margin-left: 6%;'>Secure Attachments: 
		<button onclick="saveAttachment('sn_si_physical_security_incident', gel('sys_uniqueValue').value);" id="header_add_attachment" title="" aria-label="Secure Attachments" class="btn btn-icon icon-paperclip navbar-btn" data-original-title="Secure Attachments">
		</button>
	</div>
</j:jelly>

find_real_file.png

1 ACCEPTED SOLUTION

Hmm, try this with a return false:

<?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="label-text" style ='margin-left: 6%;'>Secure Attachments: 
		<button onclick="saveAttachment('sn_si_physical_security_incident', g_form.getUniqueValue()); return false;" id="header_add_attachment" title="" aria-label="Secure Attachments" class="btn btn-icon icon-paperclip navbar-btn" data-original-title="Secure Attachments">
		</button>
	</div>
</j:jelly>

View solution in original post

5 REPLIES 5

Brad Tilton
ServiceNow Employee
ServiceNow Employee

You should be able to use g_form.getUniqueValue() to grab the sys_id of the record where your ui macro is located.

<?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="label-text" style ='margin-left: 6%;'>Secure Attachments: 
		<button onclick="saveAttachment('sn_si_physical_security_incident', g_form.getUniqueValue());" id="header_add_attachment" title="" aria-label="Secure Attachments" class="btn btn-icon icon-paperclip navbar-btn" data-original-title="Secure Attachments">
		</button>
	</div>
</j:jelly>

Hi Brad,

The pop-up appeared for a second and then it redirected to a new record. Is it suppose to replace the g_form.getUniqueValue() with the sys_id?  I'm trying to replicate the attachment icon on the top of the form. Thank you so much for your help.

 

find_real_file.png

Hmm, try this with a return false:

<?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="label-text" style ='margin-left: 6%;'>Secure Attachments: 
		<button onclick="saveAttachment('sn_si_physical_security_incident', g_form.getUniqueValue()); return false;" id="header_add_attachment" title="" aria-label="Secure Attachments" class="btn btn-icon icon-paperclip navbar-btn" data-original-title="Secure Attachments">
		</button>
	</div>
</j:jelly>

Hi Brad. That works. Thank you. 

Could you explain why we have to add the return false?