VIP indicator on Catalog Task
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-08-2018 12:52 PM
Hello Everyone
I'm trying to work to show the VIP indicator for 'Requested for' field on CTASK form. For this I chose to create a Field style with the value and style in it. Below is how I configured it, but somehow this doesn't work.
'u_task_for' is the field value for 'Requested For' on the CTASK table. When I configured the form layout, it says the field is 'Request.Requested For', so I used the same in the value field i.e. 'sc_request.u_task_for'. Not sure if this is the way. But just trying to get some suggestions to move forward.
Thanks in Advance.
Regards!
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-08-2018 02:08 PM
Dear Nitin,
1. Do you want this field style on just the form or both on form and list. Please see this note regarding field styles
Value | The exact value or script-based-condition required to apply the style. Note: The value only affects list field styles. To apply field styles on both lists and forms, leave this field blank. |
If you see my screenshot, I applied a simple style to RITM (request_item) column and you can see that it got applied to list view but not the form view as described above.
In order to change the field styles at form level you need to achieve it using a client script. In my code am making the field label as red and it appears as below.
Code developed
client script
*************
function onLoad() {
//Type appropriate comment here, and begin script below
var fieldLabel = g_form.getLabel('requested_for');
var ritm = g_form.getValue('request_item');
//alert(ritm);
var ga = new GlideAjax('checkUser');
ga.addParam('sysparm_name', 'checkVip');
ga.addParam('sysparm_user_name', ritm);
ga.getXML(HelloWorldParse);
function HelloWorldParse(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
//alert(answer);
if(answer == 'true') {
fieldLabel.style.color = 'red';
}
}
}
Script include
***************
var checkUser = Class.create();
checkUser.prototype = Object.extendsObject(AbstractAjaxProcessor, {
checkVip:function() { //return "Hello " + this.getParameter('sysparm_user_name') + "!";
var returnFlag = false;
var userId = this.getParameter('sysparm_user_name');
//var userId = '585e60020f97030067a7cd8ce1050e1d' + '';
var grUser = new GlideRecord('sc_req_item');
grUser.addQuery('sys_id', userId );
grUser.query();
if(grUser.next()) {
//gs.print(grUser.request.requested_for.vip);
returnFlag = grUser.request.requested_for.vip ;
}
//gs.print(returnFlag );
return returnFlag ;
} ,
_privateFunction: function() { // this function is not client callable
}
});
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-09-2018 09:24 AM
Thanks Anil for your detailed info. Yes I want to make it visible both on form and list view. So If I clear the value field from the Field style, It's not working either. Else If I have the value field, it's not even working on List view.
I have checked you script include and client script, Not sure if there was any reason to use script include. I was trying to achieve this directly by writing onChange client script. Created a onChange client script (VIP Indicator) by just looking at the Incident VIP indicator script and modified the field and table values accordingly. It did not work either. Not sure what's wrong it it.
function onChange(control, oldValue, newValue, isLoading) {
var callerLabel = $('label.sc_request.u_task_for');
var callerField = $('sys_display.sc_request.u_task_for');
if (!callerLabel || !callerField)
return;
if (!newValue) {
callerLabel.setStyle({backgroundImage: ""});
callerField.setStyle({color: ""});
return;
}
g_form.getReference('sc_request.u_task_for', vipCallerCallback);
}
function vipCallerCallback(caller) {
var callerLabel = $('label.sc_request.u_task_for').down('label');
var callerField = $('sys_display.sc_request.u_task_for');
if (!callerLabel || !callerField)
return;
//check for VIP status
if (sc_request.u_task_for.vip == 'true') {
var bgPosition = "95% 55%";
if (document.documentElement.getAttribute('data-doctype') == 'true')
bgPosition = "5% 45%";
callerLabel.setStyle({backgroundImage: "url(vip_user.png)", backgroundRepeat: "no-repeat", backgroundPosition: bgPosition, paddingLeft: '30px' });
callerField.setStyle({color: "red"});
} else {
callerLabel.setStyle({backgroundImage: ""});
callerField.setStyle({color: ""});
}
}
Do you think any corrections to be made in the above?
Regards!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-10-2018 06:04 AM
Dear Nitin,
Can you start with setting the color alone and see if it works?
something like this fieldLabel.style.color = 'red';
GlideAjax is a more efficient approach than get reference, hence I suggested that approach. My script works if implemented as is. Since it worked for me.
Please let me know how it goes so that I can help further.
Thanks
Anil
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-18-2018 10:54 AM
Hello Anil
VIP Indicator seems to be working now,thanks for your help. STAR icon is displayed beside the Requested for fields on REQ, RITM and CTASK if the field has VIP user in it. I have another conflict here. I'm trying to make the field value to display as red in color.
But the field color is not showing up as red on RITM's and CTASK forms.
If you see the Requested for on above image it doesn't show up in red color.
However I'm using the same script for both REQ and RITM's and both has the line of code for set color to red.
Not sure why is this happening. Field colors doesn't work on dot walked fields because requested for on ritm table is a dot walked field from REQ table.
Regards!