Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

How to set the image icon beside priority field?

prasannakumard
Tera Guru

Hi Team,

I tried to set one icon beside the Priority field. I used the following onload script (taken from Service now guru: https://www.servicenowguru.com/system-ui/ui-macros/add-macro-non-reference-field/ )

But, it is showing like this:

find_real_file.png

How to set this to beside to field.

function onLoad() {

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

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

      var field = 'priority';

      //Append the table name to get the field id

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

      try{

      //Create the image element and add to the dom

      $(field).insert({

                      after: '<a onclick="doSomething()" name="my_custom_macro" id="my_custom_macro"><img src="orange-arrow.png" alt="Show Macro" title="Show Macro" style="padding-left:4px;"></a>'

              });

      }

      catch(e){

      //alert('Error');

      }

}

//onclick event to fire when the image is clicked

function doSomething() {

    alert('You clicked me!');

}

Please suggest me how can I set this?

Thanks & Regards,

Prasanna Kumar

1 ACCEPTED SOLUTION

Finally, I fixed the issue by using following script:



function onLoad() {


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


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


var field = 'priority';


      //Append the table name to get the field id


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




      try{


      //Create the image element and add to the dom


      $(field).insert({


                      after: '<a onclick="doSomething()" name="my_custom_macro" id="my_custom_macro" style="display: block;position: absolute;top:0;right: -68px;width: 60px;height: 60px;"><img src="info-icon.png" width="32" height="32"/></a>'



              });


      }



      catch(e){


      //alert('Error');


      }


}




//onclick event to fire when the image is clicked


function doSomething(){


//HR WorkBench View and Default view


if(getView() == 'hr_workbench' || getView() == ''){


window.open('/Priority Defination - HR Fulfiller View.do','_blank');


}


else if(getView() == 'ess'){


window.open('/Priority Defination - Customer View.do','_blank');


}


}


View solution in original post

7 REPLIES 7

Inactive_Us2231
Giga Expert

Hi Prasanna,



I think this is what you are looking for,


How to add icon in field control



Please mark helful/correct based on the impact of the response



Thanks!


Thank you for your help Sandesh.   But, I need the functionality as mentioned above. Because I need to write some other script in doSomething function. So, If you have any idea about the same please let me know.


snow_dev
Tera Expert

Hi Prasanna,


Can you try adding border attribute with img tag as shown below and see if it helps:



<img border="0" src="orange-arrow.png" alt="Show Macro" title="Show Macro" style="padding-left:4px;">



Regards,


Ashish


No, Asish, I added Boarder and it is not working. Same result.