Set field value true if the caller field has a particular person

Community Alums
Not applicable

On an interaction, I have a field name 'u_external_user'. It is a checkbox (True/False).

I want to toggle this field True if the Opened for field 'opened_for' is a user named External User. I believe a client script will be the best way to do this but need advice on this and code if anyone can help.

1 ACCEPTED SOLUTION

Shamma Negi
Kilo Sage
Kilo Sage

if(g_form.getValue("opened_for") == "sys id of the external user)

{

g_form.setValue("<external_user_checkbox" , true);

}

else

 

{

g_form.setValue("<external_user_checkbox" , false);

}

Regards,Shamma Negi

View solution in original post

23 REPLIES 23

Community Alums
Not applicable

ShannonPearson_0-1702562350801.png

 

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

    if (isLoading || newValue == '') {

        return;

    }

    if (g_form.getDisplayBox('opened_for').value) == 'External User';

   {

        g_form.setValue('u_external_user', true); //when caller is external user

    }

    else {

        g_form.setValue('u_external_user', false); //when caller is NOT external user

    }

}

Community Alums
Not applicable
function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }
	var userDisplay = g_form.getDisplayBox('opened_for').value
    if (userDisplay == 'External User')
   {
        g_form.setValue('u_external_user', true); //when caller is external user
    }
    else {
        g_form.setValue('u_external_user', false); //when caller is NOT external user
    }

This code works in Platform view but not in Service Operations Workspace which is where it will predominantly be used.

Community Alums
Not applicable

This code works in Platform view but not in Service Operations Workspace which is where the users live most of the time.

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }
	var userDisplay = g_form.getDisplayBox('opened_for').value
    if (userDisplay == 'External User')
   {
        g_form.setValue('u_external_user', true); //when caller is external user
    }
    else {
        g_form.setValue('u_external_user', false); //when caller is NOT external user
    }

Have you tri4ed to add alerts to check on workspace what is not working.

Alert userDisplay and see if you get desired value

-Anurag

@Community Alums getDisplayBox won't work in the workspace side, you have to use either getReference or GlideAjax to fetch the value.

Please find below sample code for getReference:

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue === '') {
        return;
    }
    var user = g_form.getReference('opened_for', findUserDisplay);
    function findUserDisplay(user) {
        if (user.name == 'External User')
            g_form.setValue('u_external_user', true);
        else g_form.setValue('u_external_user', false);
    }
}