Can i add a button into a catalog item, on the form itself

dave_edgar
Mega Guru

I want to add a 'check availability' button onto to a catalog item form, before submit, so users can check if we have an item for example

Is there a way to do this, using a yes/no is a bit ugly but having a choice button that could trigger it would be quite nice

1 ACCEPTED SOLUTION

oharel
Kilo Sage

How about a UI macro on a string field?


Like this:


1. Add a string field to the form.


2. Add the following onLoad script:


function onLoad() {


      //The variable name to put the icon next to


      g_form.setReadOnly('available', true);


var varName = 'available';


   


      try{


              //Add the icon decoration to the reference field


          var varEl = g_form.getControl(varName).id;


              $(varEl).insert({


                      after: '<span><a id="icon-check-circle" class="btn btn-default sc-ref-spacer icon-check-circle sn-tooltip-basic" title="" data-original-title="Check availability"></a></span>'


              });


              //Add the 'onclick' event


              $('icon-check-circle').observe('click', checkAvailability);


      }catch(e){}


   


      function checkAvailability(){


              //Add current user to reference field


var check = new GlideRecord('u_new_test_table');


check.addQuery('u_num',   '1');


check.query();


if(check.next()) {


g_form.setValue(varName, 'The item is available.');


} else {


g_form.setValue(varName, 'The item is not available. Bummer.');


}


}


}



Notes:


1. icon-check-circle is the name of the icon. You can insert your own or go to Collaborate -> Administration -> Action icons and choose your own


2. The script is a modification of mark.stanger 's 'Add Me' UI macro for User and Group Fields


3. The whole checkAvailability function: replace it with your own code, using the relevant tables and items. In my example, I wanted to check whether the number '1' appears in a field called u_num.



Harel


View solution in original post

5 REPLIES 5

Community Alums
Not applicable

Hi 

I have similar requirement in that once we click on button the Date type fields(variable) are coming(highlighted) on the screen(ui page)?

may i know what is issue   

find_real_file.png