update caller to email and department name in short description dynamically

Priyansh_98
Tera Guru

Hi ALL,

 

i want to update caller's email and department name in short description when ever a incident record created on snow.

 

can any one help me with that?

 

Thanks,

1 ACCEPTED SOLUTION

@Priyansh_98 

 

Hope you are doing good.

Did my reply answer your question?

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

View solution in original post

7 REPLIES 7

Runjay Patel
Giga Sage

Hi @Priyansh_98 ,

 

Write before insert BR and use below code.

(function executeRule(current, previous /*null when async*/) {
    // Ensure there's a Caller
    if (current.caller_id) {
        // Get the Caller record
        var caller = new GlideRecord('sys_user');
        if (caller.get(current.caller_id)) {
           
            var email = caller.email;
            var departmentName = caller.department.name;
            current.short_description = 'Caller: ' +email+'  Department: '+ departmentName;
        }
    }
})(current, previous);

 

-------------------------------------------------------------------------

If you found my response helpful, please consider selecting "Accept as Solution" and marking it as "Helpful." This not only supports me but also benefits the community.


Regards
Runjay Patel - ServiceNow Solution Architect
YouTube: https://www.youtube.com/@RunjayP
LinkedIn: https://www.linkedin.com/in/runjay

-------------------------------------------------------------------------

 

In this video i have explained about Web service integration in ServiceNow like how it works, how we can configure it, what are the prerequisite and many more. I have covered below topics in this video. 1. understand Web Service. Like when and how we will use it. 2. Talked about Inbound and ...

Ankur Bawiskar
Tera Patron
Tera Patron

@Priyansh_98 

you can use before insert BR on incident table

Condition: Caller ID [IS NOT EMPTY]

Script:

(function executeRule(current, previous /*null when async*/) {
        current.short_description = 'Email: ' + current.caller_id.email + ', Department: ' + current.caller_id.department.name;
})(current, previous);

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

Priyansh_98
Tera Guru

Hi @Ankur Bawiskar ,

 

Thanks for your response...!!

 

can i do it using client script also?

i tried getreference method on client script, but i am not able to get department name. i am getting undefined..!!!

 

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

    var cl = g_form.getReference('caller_id');

    // alert(cl);
    // alert(cl.email);
    alert(g_form.getDisplayValue(cl.department));
    var email = cl.email;
    var dept = cl.department.name;

    var desc = g_form.getValue('short_description');

    var new_desc = desc + '_' + email + '_' + dept;
    g_form.setValue('short_description', new_desc);

    function callback() {
      
    }
}

 

output below..

 

Priyansh_98_0-1735026986125.png

 

Thanks,

 

@Priyansh_98 

you will have to use GlideAjax for this as you cannot dot walk 1 more level in client script.

Why not use Business rule?

It will avoid creation of script include and client script

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