Wednesday, June 28, 2017

How to add custom text and icon to fields based on specific conditions in Service Now

Requirement -
1. Based on 'Caller' attribute on Incident form, Display a text(Public Sector Employee) in red color right below the 'Caller' field

2. Display 'Red Color' icon next to 'Caller' field on 'Incident' List view


Solution

1. Create a Client script as shown below
2. Write below script
function onChange(control, oldValue, newValue, isLoading) {
var callerLabel = $('label.incident.caller_id');
var callerField = $('sys_display.incident.caller_id');
if (!callerLabel || !callerField)
return;

if (!newValue) {
callerLabel.setStyle({backgroundImage: ""});
callerField.setStyle({color: ""});
return;
}
g_form.getReference('caller_id', vipCallerCallback);
}

function vipCallerCallback(caller) {
var callerLabel = $('label.incident.caller_id').down('label');
var callerField = $('sys_display.incident.caller_id');
if (!callerLabel || !callerField)
return;
var bgPosition = "95% 55%";
//check for VIP status
if (caller.vip == 'true') {
g_form.showFieldMsg("caller_id", "VIP", "error");
if (document.documentElement.getAttribute('data-doctype') == 'true')

callerField.setStyle({color: "red"});
}
// Check for federal status
else if(caller.u_company_cd == '198'){

g_form.showFieldMsg("caller_id", "Public Sector Employee", "error");
if (document.documentElement.getAttribute('data-doctype') == 'true')

callerField.setStyle({color: "red"});
}

else {
callerLabel.setStyle({backgroundImage: ""});
callerField.setStyle({color: ""});

}
}

3. Create a below style , to show 'red color' icon next to 'Caller' field in Incident List view.





12 comments:

  1. Excellent website. Lots of useful information here, thanks in your effort! . For more information please visit

    servicenow online course

    ReplyDelete
  2. Thank you for sharing the useful information . It helped me a lot . Servicenow online training

    ReplyDelete
  3. the blog is aboutService Now Business Rules Assignments it is useful for students and servicenow Developers for more updates on servicenow follow the link

    ServiceNow Online course Hyderabad

    For more info on other technologies go with below links

    tableau online training hyderabad

    Python Online Training

    mulesoft Online Training


    ReplyDelete
  4. well done the blog is great and it is about How to add custom text and icon to fields based on specific conditions in Service Now it is useful for students and servicenow Developers for more updates on servicenow follow the linkServiceNow Online Training

    ReplyDelete
  5. This comment has been removed by the author.

    ReplyDelete
  6. This comment has been removed by the author.

    ReplyDelete
  7. interesting information. This is just the kind of information that i had been looking for, i'm already your rss reader now and i would regularly watch out for the new posts,Thank you for sharing your valuable information .
    ServiceNow training in Hyderabad

    ReplyDelete
  8. I read your blog it's really amazing It has good content share more article on ServiceNow Online course hyderabad

    ReplyDelete
  9. No one can stop you writing a perfect blog or article if you are passionate to your job. Your aim is to satisfy your readers with a well written blog and your passion is always behind your every successful assignment. Impressive writing skills can be observed over here.
    chauffeur mykonos

    ReplyDelete
  10. Wow it is really wonderful and awesome thus it is veWow it is really wonderful and awesome thus it is very much useful for me to understand many concepts and helped me a lot. it is really explainable very well and i got more information from your site.ry much useful for me to understand many concepts and helped me a lot. it is really explainable very well and i got more information from your site.servicenow training in bangalore

    ReplyDelete