Trying to do CAD certification how to get firstname? The following doesn't work.

hikerclimber
Giga Guru

Hi,

 

In the training it states that this gets the firstname: 'g_user.firstName'. However I get the following when I run the code:

 

"incident.System"

 

Any suggestions?

 

Thanks,

Aniket

2 REPLIES 2

sivasankaris
Tera Guru

Hi @hikerclimber ,

Here are two valid reasons why g_user.firstName returns the system

 

1️⃣ You’re logged in as System Administrator

  • The default admin user has:

    • First name: System

    • Last name: Administrator

  • So g_user.firstName correctly returns System

  • Verify by checking your user record or impersonating another user (e.g., Abel Tuter)

 

2️⃣ The script is running in a non-interactive (server-side) context

In these cases, ServiceNow runs the code as System, regardless of who triggered it:

  • Business Rules (async / background)

  • Flow Designer actions

  • Scheduled Jobs

  • Script Includes (called server-side)

  • Integrations / APIs

In all these scenarios, no real user session exists, so: g_user.firstName"System" 

 

If this is useful, Please Mark it as helpful and Please Accept My Solution...

Best Regards,

SIVASANKARI S

Tanushree Maiti
Kilo Patron

Validate the User first name again in your system. Try with different user once .

e.g  for System Administrator user (default one)

alert(“g_user.firstName = “ + g_user.firstName + “, \n g_user.lastName = “ + g_user.lastName + “, \n g_user.userName = “ + g_user.userName + “, \n g_user.userID = “ + g_user.userID);

 

Above will return

TanushreeMaiti_0-1771044090160.png

 

Please mark this response as Helpful & Accept it as solution if it assisted you with your question.
Regards
Tanushree Maiti
ServiceNow Technical Architect
Linkedin: