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.

Populate selected user name once attestation checkbox is checked

Renu9
Tera Contributor

Hi All,

I am having a requirement in one catalog item with 1 checkbox variable - Attestation. Once this is checked, next to this variable , I need to display the name of the person which is available in Requested for.

Label should not appear, only name should be visible . Is this possible?

6 REPLIES 6

Sandeep Rajput
Tera Patron
Tera Patron

@Renu9 I doubt if you would be able to capture the Requested for name on a variable before the catalog item is submitted using a client script. 

AshishKM
Kilo Patron
Kilo Patron

Hi @Renu9 , 

You can try with onChange catalog client script on checkbox variable. 

Create a single line text field and set name of requested for person name and try below code to hide the label

 

g_form.setLabelOf('<field_name>',''); // replace the field name

 

-Thanks,

AshishKM


Please mark this response as correct and helpful if it helps you can mark more that one reply as accepted solution

According to https://developer.servicenow.com/dev.do#!/reference/api/washingtondc/client/c_GlideFormAPI#r_GlideFo... setLabelOf(String fieldName, String label) is not supported by Service Catalog.

SomaSekharSane_0-1720444751997.png

 

SAI VENKATESH
Kilo Patron
Kilo Patron

Hi @Renu9 

 

Just Now I have tried in my PDI by creating two variables 

1: as mentioned by you creation of check box called " Attestation"

2: creation of HTML field and made it Read Only. and also as mentioned by you label will not appear and I made setLabelof to NULL;

Below is the code and the images:

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue === '') {
		g_form.setLabelOf('Requestforpopulate', ' '); // name of HTML field 
        return;
    }

    // Asynchronously get the value of the 'user_name' field and process it with the callback function
    g_form.getReference('user_name', callback);

    function callback(data) {
        if (data) {
            var userFullName = data.name;

            // Display the name next to the checkbox with rich text formatting
            if (newValue === 'true') {
                g_form.setValue('Requestforpopulate', '\t' + userFullName); //// name of HTML field 
            } else {
                g_form.setValue('Requestforpopulate', ''); // name of HTML field 
            }
        }
    }
}

 

when selected:

cn298.PNG

when not selected:

cn297.PNG

 

Thanks and Regards

Sai Venkatesh