UI Macro to display an icon on a reference field

scot_sutton
Tera Contributor

I need assistance developing a UI Macro to display an icon on a reference field, field_1, if the current user is a member of the group specified in another reference field, field_2. I already have a UI Macro, add_me, written to populate the current user into field_1 and the code to determine if the current user is a member of the group specified in field_2 (as a Script Include, userIsMemberOfGroup). What I cannot figure out is the code to make the visibility of the icon dependent on the membership of the current user in the group specified in field_2. My jelly expertise is somewhere around the novice level so any assistance would be appreciated.

7 REPLIES 7

srinivasthelu
Tera Guru

HI Scot,


Can you paste the current UI Macro code once here?



thanks


srini


srinivasthelu
Tera Guru

Hi Scott,



ok, If your UI Macro as a line(something like this) <g:reference_decoration id="${jvar_n}" field="${ref}">



Then reference_decoration is the another macro controlling the visibility of your ICON. By default, It will only check for non empty value.



You need to create a new UI macro per say reference_decoration1(a copy of reference_decoration) and modify decorationShow function in it.   Once you have this UI Macro is ready, use this in your original UI Macro by <g:reference_decoration1 id="${jvar_n}" field="${ref}">.



Hope this helps


Srini


Thanks Srini.



So, I see that the UI Macro reference_decoration has the code:



// show link if populated, hide if not


// move to js file for multiple inclusion


function decorationShow(element, original, changed, loading) {


  var visibility = 'hidden';


    if (changed.length > 0) {


          var parentTr = gel('element.' + element.id);


          if (!(parentTr $[AMP]$[AMP] parentTr.style.visibility == 'hidden'))


                visibility = 'visible';


    }



  var e = gel('${jvar_id}');


  e.style.visibility= visibility;


}



I understand this code but this just uses "if (changed.length > 0)" to determine if the target field is empty.


What I need is a method to reference another field on the record (field_2 in my example above) so that I can perform a test using that value.


For example, I need to be able to call a Script include (userIsMemberOfGroup in this example) such as:


  var visibility = 'hidden';


  var visibleFlag = userIsMemberOfGroup(field_2.DisplayValue(),'$[gs.getUserID()]')


if (visibleFlag)


                visibility = 'visible';


  }


Hi Scot,



Yes. You would need to write a GlideAjax with client callable script include to verify user belonging to the group.



Let me know if you need any further help.



Mark this answer as helpful/correct if it does so.



Srini