Reference

aniellacerna
Tera Contributor

what reference should I use in a variable "Requested For's Manager" That is Auto-populated with Requested For's Manager

4 REPLIES 4

SN_Learn
Kilo Patron
Kilo Patron

Hi @aniellacerna ,

 

I believe you are trying to auto-populate the Requested for's manager when Requested for is selected.

 

In order to achieve this, you can try the below:

The type of field for 'Requested For's Manager' will be reference and then write a 'onChange' catalog client script

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }
    var reqForUser = g_form.getReference('requested_for', getMgr);

    function getMgr(reqForUser) {
        g_form.setValue('manager', reqForUser.manager);
    }
}

 

Please accept my answer and mark this helpful if it helps. 

----------------------------------------------------------------
Mark this as Helpful / Accept the Solution if this helps.

Danish Bhairag2
Tera Sage
Tera Sage

Hi @aniellacerna ,

 

You can try the Auto-populate feature in servicenow.No need for any scripting.

Open the requested for manager field there u should be able to find the Auto-populate tab. Just fill it like below.

 

DanishBhairag2_0-1699706831771.png

 

For additional info plz go through the below link:

https://www.servicenow.com/community/developer-articles/auto-populate-reference-data-in-service-cata...

 

Thanks,

Danish

 

 

Harish Bainsla
Tera Sage
Tera Sage

Hi there are two ways to do first with client script and script include

function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var reqFor = g_form.getReference('requested_for', Mgr);

function Mgr(reqFor) {
g_form.setValue('manager', reqFor.manager);
}
}

and for script include watch below video

https://youtu.be/svKX5KELh44?si=-SIcYXKPOBWPHPy4

Script Include in ServiceNow with Scenario | Types of Script Include with Examples #ServiceNow - Script Include is very important topic in ServiceNow, It will help you to play with codes & it will make your life easy in term of any enhancement or customization you have to perform as part of ...

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @aniellacerna 

 

If you creating a new field for Manager Approval - Please user user table for reference. 

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************