Interested in a ServiceNow event built for developers? Registration for now[dev]26 is officially open!

Autopopulate the Manager field in the catalog item.

Servicenow de11
Tera Contributor

Hello,

 

I need to automatically populate the Approving Manager variable in a ServiceNow catalog item based on the following logic:

  • If the Is this request for you? variable is Yes, then the manager of the Requested by user should be auto-populated in the Approving Manager field.
  • If the Is this request for you? variable is No, then the manager of the user specified in the On Behalf of variable should be auto-populated in the Approving Manager field.

Could someone guide me on how to implement this?

 

Thanks in advance

 

8 REPLIES 8

Servicenow de11
Tera Contributor
 

Ankur Bawiskar
Tera Patron

@Servicenow de11 

something like this in onchange catalog client script

Ensure you give correct variable names

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

    if (newValue == '') {
        g_form.clearValue('approving_manager'); // approving manager variable name here
    }
    var variableToPick = '';
	
    if (newValue == 'yes')
        variableToPick = 'requested_by'; // requested by variable name
    else if (newValue == 'no')
        variableToPick = 'on_behalf_of'; // on behalf of variable name

    var ref = g_form.getReference(variableToPick, callBackMethod);
}

function callBackMethod(ref) {
    if (ref.manager)
        g_form.setValue('approving_manager', ref.manager); // approving manager variable name here
}

💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏

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

Hello Ankur,

 

I have tried with the above script but it is not auto populating.
All those variable are existing in the variable set. I wrote the above client script in the variable set itself

 

Thanks

@Servicenow de11 

it should work fine provided you are comparing correct values and correct variable names

share your client script screenshot along with variable backend name etc

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