Adding a button next to field on form

codedude
Mega Expert

I am trying to add a button next to a field on a form in ServiceNow. I know you can add a button in the banner, list, etc, but I am wanting to add it to the form next to the field. I will show image below.

I want to add this button

button.PNG

Next to this field on the form, not in the banner like it currently is

field.PNG

6 REPLIES 6

Tim Deniston
Mega Sage
Mega Sage

Sounds like you need a UI Macro.



Wiki documentation: UI Macros - ServiceNow Wiki


Examples of UI Macros: UI macros Archives - ServiceNow Guru



You should be able to use the examples on the second link to build exactly what you're trying to do.


kazidon
Giga Contributor

I know this is older but I was trying to do this and found a pretty good solution. What I ended up doing is creating a UI Macro, then referencing that UI Macro in the field attributes. In the UI macro I had that reference a UI page and was able to write my code there using html, client scripts... etc..

 

here is my 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">
<g:evaluate var="jvar_guid" expression="gs.generateGUID(this);" />
<j:set var="jvar_n" value="show_incidents_${jvar_guid}:${ref}"/>
<g:reference_decoration id="${jvar_n}" field="${ref}" 
  onclick="cancelITRecord('${ref}'); "
  title="${gs.getMessage('Cancel IT Record')}" image="images/icons/tasks.gifx" icon="icon-workflow-rejected" />

<script>

function cancelITRecord(reference) {
	
  	var w = new GlideDialogWindow('cancel_it_offboarding_record'); //This is the name of the UI page I created.
  	w.setTitle("");
  	w.render();
}

</script>
</j:jelly> 

this is what I put next to the field to reference the UI macro. right click on field and go to dictionary click on advanced view under related links and put this in Attributes


ref_contributions=cancel_it_record

 

cancel_it_record is the name of the UI Macro above, replace it with the name of your UI Macro.

 

create your UI page add HTML and client scripts and processing scripts and your done!