Linker caller to a choice field

Neil_Carlo24
Tera Contributor

Hello,

I want to link a one caller/user to a choice field. Ex. Bill hill = User, TeamDesk  = (Helpdesk Team - Choice field). If bill selected on the caller will automatically Helpdesk Team will populated.

18 REPLIES 18

Aniket Chavan
Tera Sage
Tera Sage

Hello @Neil_Carlo24 ,

Okay so you just need to make some changes in your script.

 

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

    var caller = g_form.getValue('caller_id');

    // Assuming 'caller_id' and 'u_helpdesk_team' are the correct field names
    if (caller == '98dde0c61b1f95100531ed7de54bcb3f') {
        g_form.setValue('u_helpdesk_team', 'SSC');
    }
}

 

 

Let me know your views on this and Mark Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.

 

Thanks,

Aniket

Aniket Chavan
Tera Sage
Tera Sage

Hello @Neil_Carlo24 


Is there any update on my response? if my response was helpful in addressing your query or If it assisted you in resolving your issue, kindly consider marking it as helpful, accepting the solution, and closing the thread. Doing so will not only acknowledge the assistance provided but also benefit future readers who might encounter a similar problem.


Thank you! 😁


Aniket.

sourav1999
Mega Guru

Sure, you can achieve this by using a client script in ServiceNow. Here's a step-by-step guide:

1. Navigate to System Definition > Client Scripts in ServiceNow.
2. Click on New to create a new client script.
3. Fill in the necessary fields:
- Name: Give a name to your client script.
- Table: Select the table where you want this script to run (for example, Incident).
- Type: Select "onChange".
- Field name: Select the field that should trigger this script (in your case, Caller).
4. In the Script field, write your JavaScript code. Here's a sample code:

javascript
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var user = g_form.getReference('caller_id', setUserFields); // 'caller_id' is the field name of the Caller
}

function setUserFields(user) {
if (user.u_teamdesk == 'Helpdesk Team') { // 'u_teamdesk' is the field name of the TeamDesk
g_form.setValue('u_teamdesk', 'Helpdesk Team'); // 'u_teamdesk' is the field name of the TeamDesk
}
}

5. Click on Submit to save the client script.

 

For asking ServiceNow-related questions try this :
For a better and more optimistic result, please visit this website. It uses a Chat Generative Pre-Trained Transformer ( GPT ) technology for solving ServiceNow-related issues.
Link - nowgpt.ai

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @Neil_Carlo24 

 

You can use Assignment rule or look up rule for this.

https://youtu.be/PuOT2EGrGY4

 

*************************************************************************************************************
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]

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