UI Macro (alert icon) show conditionally beside a reference field variable in a record producer

Community Alums
Not applicable

I am trying to have a UI macro that display any icon (conditionally) upon selection of a Service (reference field) on the incident record producer in service portal to redirect the user to a different page (upon clicking the icon). I was able to achieve this easily in the advanced UI for any reference field by mentioning the UI macro name in the respective field's attribute.

How do we achieve the same functionality in service portal. Is it possible? If not, I would just go with a message containing URL to redirect the user to a different page

4 REPLIES 4

Sai Kumar B
Mega Sage
Mega Sage

@Sanjay Gorityala have you tried mentioning the UI macro in variable attributes? 

I haven't tested it, Give it a try if no luck

Use the below sample catalog client script

Source: https://servicenowguru.com/system-ui/ui-macros/add-me-ui-macro-user-group-fields/

function onLoad() {
    //The variable name to put the icon next to
    var varName = 'caller_id';
   
    try{
        //Add the icon decoration to the reference field
        //If not reference variable, remove 'lookup.' below
        var varEl = 'lookup.' + g_form.getControl(varName).id;
        $(varEl).insert({
            after: '<span><a id="add_me_macro" class="btn btn-default sc-ref-spacer icon-user sn-tooltip-basic" title="" data-original-title="Add me"></a></span>'
        });
        //Add the 'onclick' event
        $('add_me_macro').observe('click', addMe);
    }catch(e){}
   
    function addMe(){
        //Add current user to reference field
        g_form.setValue(varName, g_user.userID);
    }
}

Community Alums
Not applicable

Yes - I already tried to mention the UI macro name in the variable attributes. Also tried the above script. Nothing shows up

To be precise, the following line returned undefined

g_form.getControl(varName).id;

@Sanjay Gorityala Could you try the below if it's returning undefined

var form = typeof g_sc_form != "undefined" ? g_sc_form : g_form; 
var myControl = form.getControl("VARIABLE"); 

Source : https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0547171

Community Alums
Not applicable

No, it is not working either. From the above script myControl returns "Object". However, myControl.id returns undefined again.