Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

highlight vip user in catalog task

Ralton Stewart
Tera Guru

I am in need of some help please. When a VIP user creates a Service Request I have it setup that that the users names is Highlighted, when I click into the RITM and SCTask it fails to highlight the name. Attached are some screen grabs and the client script.

 

I tried with Onchange and Onload as well changing the table to sc_req_item.

 

function onChange(control, oldValue, newValue, isLoading) {
    var callerLabel = $('label.sc_request.requested_for');
    var callerField = $('sys_display.sc_request.requested_for');
    if (!callerLabel || !callerField)
        return;

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

function vipCallerCallback(caller) {
    var callerLabel = $('label.sc_request.requested_for').down('label');
    var callerField = $('sys_display.sc_request.requested_for');
    if (!callerLabel || !callerField)
        return;

    //check for VIP status
    if (caller.vip == 'true') {
        var bgPosition = "95% 55%";
        if (document.documentElement.getAttribute('data-doctype') == 'true')
            bgPosition = "5% 45%";

        callerLabel.setStyle({
            backgroundImage: "url(images/icons/vip.gif)",
            backgroundRepeat: "no-repeat",
            backgroundPosition: bgPosition,
            paddingLeft: '30px'
        });
        callerField.setStyle({
            color: "red"
        });
    } else {
        callerLabel.setStyle({
            backgroundImage: ""
        });
        callerField.setStyle({
            color: ""
        });
    }
}
 
 
 
 
 
This code was for Requested Item 
function onChange(control, oldValue, newValue, isLoading) {
    var callerLabel = $('label.sc_req_item.request.requested_for');
    var callerField = $('sys_display.sc_req_item.request.requested_for');
    if (!callerLabel || !callerField)
        return;

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

function vipCallerCallback(caller) {
    var callerLabel = $('label.sc_req_item.request.requested_for').down('label');
    var callerField = $('sys_display.sc_req_item.request.requested_for');
    if (!callerLabel || !callerField)
        return;

    //check for VIP status
    if (caller.vip == 'true') {
        console.log("Reached");
        var bgPosition = "95% 55%";
        if (document.documentElement.getAttribute('data-doctype') == 'true')
            bgPosition = "5% 45%";

        callerLabel.setStyle({
            backgroundImage: "url(images/icons/vip.gif)",
            backgroundRepeat: "no-repeat",
            backgroundPosition: bgPosition,
            paddingLeft: '30px'
        });
        callerField.setStyle({
            color: "red"
        });
    } else {
        callerLabel.setStyle({
            backgroundImage: ""
        });
        callerField.setStyle({
            color: ""
        });
    }
}
1 ACCEPTED SOLUTION

Hi @Ralton Stewart 

 

I can see in your ritm form screenshot, the "requested for" field is not local to ritm but its coming from "request" (request.requested_for)

 

It should be like this,  

 

VishalBirajdar_0-1699611274827.png

 

So you can get the requested for field on ritm using form configuration

 

                                                               OR

 

If you want to create functionality on "request.requested_for" field then you can use the logic from my previous post  where i have done the same for sc_task

 

here on sc_task, requested_for field is came form ritm 

 

VishalBirajdar_1-1699611424810.png

 

 

 

 

Vishal Birajdar
ServiceNow Developer

I know one thing, and that is that I know nothing.
- Socrates

View solution in original post

7 REPLIES 7

Vishal Birajdar
Giga Sage

Hi @Ralton Stewart 

 

I have tried on sc_req_item table : 

 

uncheck the "Isolate script" option

onChange of requested for :

 

 

 

function onChange(control, oldValue, newValue, isLoading) {
	var callerLabel = $('label.sc_req_item.requested_for');
	var callerField = $('sys_display.sc_req_item.requested_for');
	if (!callerLabel || !callerField)
		return;
	
	if (!newValue) {
		callerLabel.setStyle({backgroundImage: ""});
		callerField.setStyle({color: ""});
		return;
	}
	g_form.getReference('requested_for', vipCallerCallback);
}

function vipCallerCallback(caller) {
	var callerLabel = $('label.sc_req_item.requested_for').down('label');
	var callerField = $('sys_display.sc_req_item.requested_for');
	if (!callerLabel || !callerField)
		return;
	
	//check for VIP status
	if (caller.vip == 'true') {
		var bgPosition = "95% 55%";
		if (document.documentElement.getAttribute('data-doctype') == 'true')
			bgPosition = "5% 45%";
			
		callerLabel.setStyle({backgroundImage: "url(images/icons/vip.gif)", backgroundRepeat: "no-repeat", backgroundPosition: bgPosition, paddingLeft: '30px' });
		callerField.setStyle({color: "red"});
	} else {
		callerLabel.setStyle({backgroundImage: ""});
		callerField.setStyle({color: ""});
	}
}

 

 

 

 

Output : 

VishalBirajdar_0-1697026597827.png

 

For opened by : you can use 

 

$('label.sc_req_item.opened_by');
$('sys_display.sc_req_item.opened_by');
 
 
For catalog task :
Use onLoad Client script on sc_task 
 

 

function onLoad() {

	var requested_for = g_form.getValue('request_item.requested_for');

    var callerLabel = $('label.sc_task.request_item.requested_for');
    var callerField = $('sys_display.sc_task.request_item.requested_for');

	//alert("Label=" + callerLabel);
	//	alert("Field=" + callerField);

    if (!callerLabel || !callerField)
        return;

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

    function vipCallerCallback(caller) {
		//alert('inside vipCaller');
        var callerLabel = $('label.sc_task.request_item.requested_for').down('label');
        var callerField = $('sys_display.sc_task.request_item.requested_for');
        if (!callerLabel || !callerField)
            return;

        //check for VIP status
        if (caller.vip == 'true') {
            var bgPosition = "95% 55%";
            if (document.documentElement.getAttribute('data-doctype') == 'true')
                bgPosition = "5% 45%";

            callerLabel.setStyle({
                backgroundImage: "url(images/icons/vip.gif)",
                backgroundRepeat: "no-repeat",
                backgroundPosition: bgPosition,
                paddingLeft: '30px'
            });
            callerField.setStyle({
                color: "red"
            });
        } else {
            callerLabel.setStyle({
                backgroundImage: ""
            });
            callerField.setStyle({
                color: ""
            });
        }

    }

 

 

 

Output : 

VishalBirajdar_0-1697027978128.png

 

 

 

 

Vishal Birajdar
ServiceNow Developer

I know one thing, and that is that I know nothing.
- Socrates

@Vishal Birajdar I think it's user error on my part but I am not able to highlight requested for are you able to talk me through the steps please?

RaltonStewart_0-1699609586740.pngRaltonStewart_1-1699609693176.png

 

RaltonStewart_2-1699609763626.png

 

Hi @Ralton Stewart 

 

I can see in your ritm form screenshot, the "requested for" field is not local to ritm but its coming from "request" (request.requested_for)

 

It should be like this,  

 

VishalBirajdar_0-1699611274827.png

 

So you can get the requested for field on ritm using form configuration

 

                                                               OR

 

If you want to create functionality on "request.requested_for" field then you can use the logic from my previous post  where i have done the same for sc_task

 

here on sc_task, requested_for field is came form ritm 

 

VishalBirajdar_1-1699611424810.png

 

 

 

 

Vishal Birajdar
ServiceNow Developer

I know one thing, and that is that I know nothing.
- Socrates

Ralton Stewart
Tera Guru

@Vishal Birajdar thanks for this allow me some time to have a play and I will reach back out. It is much appreciated