Issue with Catalog Client Script to set location

Kasia5
Tera Contributor

Hi All,

 

I have an issue with my Catalog Client Script related to set the location in Single Line Text variable based on user's location from another variable ('requested_for')

 

Currently it looks like:

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }

    //Type appropriate comment here, and begin script below
    var affectedUser = g_form.getReference('requested_for', doAlert);

    function doAlert(affectedUser) {
        if (affectedUser) {
            g_form.setValue('requested_for_location', affectedUser.location);
        }
    }
}

 

and it was working fine my 'requested_for_location' field was a Reference field not a SIngle Line Text field.

When it is a Single Line Text filed then it gives me a sys_id value,,

Do you know how can I chnage the script to receive 'normal' string value in this Single Line Text field?

 

Thanks in advance for help!

6 REPLIES 6

Peter Bodelier
Giga Sage

Hi @Kasia5 

 

Try this:

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }

    //Type appropriate comment here, and begin script below
    var affectedUser = g_form.getReference('requested_for', doAlert);

    function doAlert(affectedUser) {
        if (affectedUser) {
            g_form.setValue('requested_for_location', affectedUser.getDisplayValue('location'));
        }
    }
}

Help others to find a correct solution by marking the appropriate response as accepted solution and helpful.

Danish Bhairag2
Tera Sage

Hi @Kasia5 ,

 

Can u try using this 

g_form.getDisplayBox('<field name>').value;

 

Please mark my answer helpful & accepted if it resolves your query.

 

Regards,

Danish Bhairagdar

Ankur Bawiskar
Tera Patron
Tera Patron

@Kasia5 

you cannot dot walk 2 level using getReference and also getDisplayValue() I doubt won't work in client side.

So you need to use GlideAjax only as the last option

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi @Ankur Bawiskar,

I thought that as well, but it just works 😄

 

PeterBodelier_0-1695307000824.png

 


Help others to find a correct solution by marking the appropriate response as accepted solution and helpful.