We're reclaiming inactive PDIs to keep them available for active builders. Learn what's changing, who's affected, and how to protect your work. Read More

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

mdraehan903
Tera Contributor

@Vishal Birajdar @Ralton Stewart I am trying with request.requested_for but I am not getting the output. Any reason why it could be?

function onChange(control, oldValue, newValue, isLoading) {

    console.log('Label: ', $('label.sc_req_item.request.requested_for'));

    console.log('Field: ', $('sys_display.sc_req_item.request.requested_for'));

    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('request.requested_for', vipCallerCallback);

}

function vipCallerCallback(caller) {

    console.log("Inside callback. Caller object:", caller);

    var callerLabel = $('label.sc_req_item.request.requested_for');

    var callerField = $('sys_display.sc_req_item.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: ""});

    }

}

 

Hi @mdraehan903 

 

Can you check if Isolate script option on client script is checked or unchecked.

It should be unchecked.

 

Vishal Birajdar
ServiceNow Developer

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

hi @Vishal Birajdar 
the isolate script option is unchecked. It seems to only work when requested_for is present in the form layout else the client script doesn't work on request.requested_for. Maybe it could be the field on client script that is selected which only shows as Requested for. Hence, I tried adding requested_for to the form layout and hid it with UI policy, and now the client script runs on request.requested_for. But just wanted to see if it can be done without the need of requested_for being added to form layout and using UI policy.