Creating an image button similar to "bulb" image for suggestion

Sagar Patro
Kilo Guru

I want to add an image at the end of the short description of incident form similar to the "bulb" image.
Is there a way to do this?
Please suggest if any.


Thank you
Vidyasagar

1 ACCEPTED SOLUTION

garyopela
ServiceNow Employee
ServiceNow Employee

Vidyasagar,

You can create a UI Macro and then list the UI macro in the attributes field.
The image would be linked inside the UI Macro.

To see some example UI Macros you might have in your instance, go to UI Macros and search where XML Contains g:reference_decoration and this will help you find some that have images attached. Just copy it and change the image to one you have already uploaded, then take the name of the UI Macro and place it in the attributes field in the definition record of the field to which you want the clickable image attached.


View solution in original post

12 REPLIES 12

Ankit28
Kilo Contributor

Hello Sagar,



Can you provide your code or help me in my requirement.



Requirement:Create a manual control to implement chase count.   This can be done by creating a UI macro that shows an image (similar to images that appear with reference fields) or a link next to the field.   The UI macro should display an icon (probably a plus sign) or use a link that is clickable and, on click will increment the counter.


RKumar3
Tera Guru

I suspect UI Macro mechanism works for reference fields only. To add an icon next to a non-reference field you need an onLoad client script. Please refer below link for the same. it should help you.


» How to Add a UI Macro to a Non-reference Field in ServiceNow



If you want to add some action on click of this icon refer below link as well.



http://www.servicenowguru.com/system-ui/glidedialogwindow-advanced-popups-ui-pages/


Ankit28
Kilo Contributor

The client script below adds the plus image and gives the alert but it does not increments the chase count, can you please help:


 


function onLoad() {




      //Add a UI macro
to a non-reference field




      //Set the name of
the field in the 'field' variable




      var field = 'u_chase_count';




      //Append the table
name to get the field id




      field =
g_form.tableName + '.' + field;







    try{




      //Create the image
element and add to the dom




      var img =
document.createElement('img');




      img.src =
'plussymbol.pngx';




      img.alt='Chase
Count Incrementer';




      img.title='Chase
Count Incrementer';




      var link =
document.createElement('a');




      if
(navigator.appName == 'Microsoft Internet Explorer'){




         
link.setAttribute('onclick', Function('doSomething()'));




      }




      else{




            link.setAttribute('onclick',
'doSomething()');




      }  




                              link.name='chase_count_incrementer';




   
link.id='chase_count_incrementer';




   
link.appendChild(img);




   
document.getElementById(field).parentNode.appendChild(link);




      }




      catch(e){




         
//alert('Error');




      }




}







//onclick event to fire when the image is clicked




function
doSomething() {




                              var
temp = g_form.getValue('u_chase_count');




                              temp
++;




                              alert('You
incremented the Chase Count!');




}


Please use below doSomething() function and you are done.



function doSomething() {


  var temp = g_form.getValue('u_chase_count');


  temp++;


  g_form.setValue('u_chase_count',temp);


  alert('You incremented the Chase Count!');


}


Ankit28
Kilo Contributor

I have used below function because we don't want to give alert out but use field info message, similar to what we use when an incident has a VIP as the caller (without the flashing).   We don't want to
force the user to click on the alert box each time to make it go away. Also, can the message say 'Chase counter incremented from X to Y.'? If I use 0 to 1 first time how will i change it to 1 to 2 next time?

function doSomething() {


var temp;


temp = g_form.getValue('u_chase_count');


temp ++;


g_form.setValue('u_chase_count', temp);


g_form.showFieldMsg('u_chase_count','Chase counter incremented from 0 to 1','info');


}