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

@Priyansh_98 

sample code for client script + GlideAjax

var UpdateCallerInfo = Class.create();
UpdateCallerInfo.prototype = Object.extendsObject(AbstractAjaxProcessor, {
    getCallerInfo: function() {
        var caller = new GlideRecord('sys_user');
        if (caller.get(this.getParameter('sysparm_caller'))) {
            var callerEmail = caller.email.toString();
            var callerDepartment = caller.department.getDisplayValue();
            var result = {
                email: callerEmail,
                department: callerDepartment
            };
            return JSON.stringify(result);
        }
        return null;
    }
});

Client script

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

    var ga = new GlideAjax('UpdateCallerInfo');
    ga.addParam('sysparm_name', 'getCallerInfo');
    ga.addParam('sysparm_callerId', newValue);
    ga.getXMLAnswer(function(response) {
        var result = JSON.parse(response);
        if (result) {
            var shortDescription = 'Email: ' + result.email + ', Department: ' + result.department;
            g_form.setValue('short_description', shortDescription);
        }
    });
}

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 

I hope I have provided a thorough answer to your question. I'm confident that with your developer skills, you can take it further from here.

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 

 

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