How can I print out a message in the system log?

med1
Kilo Contributor

Hi all, Im new to ServiceNow I would like some help with:

How can I print out a message in the system log?

The workflow assigned to this catalogue item should print out a log in the system logs to say "User <name of the user> has ordered more <RAM or CPU> for server <server name>". The same message should be written also in the Work Notes field of the Requested Item. Set the

state of the RITM to Closed complete after writing the messages in the previous step.

Many thanks!

 

30 REPLIES 30

I tried to use a Script include. where exactly should I put your code? And what options should i mark (client callable, caller access ect...)?

Aman Singh_
Kilo Sage

Hi Med,

You can try using gs.info('message','source'). This will also add a log record in the sys_log table.

 

Regards,

Aman

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

it would be like this

Ensure you give the variable name which has choices as RAM or CPU and the server variable

var message = 'User ' + current.request.requested_for.name + ' has ordered more ' + current.variables.variableName + ' for server ' + current.variables.serverVariable.getDisplayValue();

current.work_notes = message; // for setting in work notes

gs.info(message); // for printing in logs

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Hi 

 

In what kind of script do I have to put this code?

 

 

Thanks for the reply

Hi,

in the workflow run script.

the workflow is for your catalog item

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader