is my script include and client script is correct or not to get the user full name in description

srilekhac
Tera Contributor
var GetUserFullName = Class.create();
GetUserFullName.prototype = Object.extendsObject(AbstractAjaxProcessor, {
    initialize: function() {
},
getFullName: function() {
        var user = gs.getUser();
        var fullname = user.getFirstName() + " " + user.getLastName();

        gs.log("Full name retrieved: " + fullname, "GetUserFullName");
        return fullname;
    },

    type: 'GetUserFullName'
});
7 REPLIES 7

Bhimashankar H
Mega Sage

Hi @srilekhac ,

 

yeah it seems correct, but why are you logging message in script include.

Remove the gs.log() line. It is already returning the full name of use to called functions.

 

Good script!

 

Thanks,
Bhimashankar H

 

-------------------------------------------------------------------------------------------------
If my response points you in the right directions, please consider marking it as 'Helpful' & 'Correct'. Thanks!

Ankur Bawiskar
Tera Patron
Tera Patron

@srilekhac 

client callable script should not have initialize() method

This will work provided you are making the correct GlideAjax syntax from client side

1) if client script and script include are in different scope 

-> make sure you call the script include with the API name

-> make Accessible from -> All Application Scope

2) if client script and script include are in same scope -> no worry

var GetUserFullName = Class.create();
GetUserFullName.prototype = Object.extendsObject(AbstractAjaxProcessor, {

    getFullName: function() {
        var user = gs.getUser();
        var fullname = user.getFirstName + " " + user.getLastName();
        gs.info("Full name retrieved: " + fullname, "GetUserFullName");
        return fullname;
    },

    type: 'GetUserFullName'
});

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

@srilekhac 

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

Viraj Hudlikar
Giga Sage

Hello @srilekhac 

 

You just provided script include which has logic proper but the script include if it need to called from Client Script the script include must be marked as client callable. Once that is done your client script will be able to call script include.

Also, in your code the concatenate logic you have use is also fine but there is another method you can utilize

 
var user = gs.getUser();
var fullname = user.getDisplayName(); // this will get fullName of login user.

 

If my response has helped you hit helpful button and if your concern is solved do mark my response as correct.

 

Thanks & Regards
Viraj Hudlikar.