UI Macro (alert icon) show conditionally beside a reference field variable in a record producer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-01-2022 09:40 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-01-2022 09:51 PM
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);
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-02-2022 12:17 AM
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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-02-2022 12:29 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-02-2022 06:53 AM
No, it is not working either. From the above script myControl returns "Object". However, myControl.id returns undefined again.