gs.log()

Vignesha Priya
Tera Contributor

var checking_user_is_part_of_specific_Group = Class.create();
checking_user_is_part_of_specific_Group.prototype = {
initialize: function() {
},

isUserPartOfGroups: function(groupNames) {
var chg = new GlideRecord('change_request');
var user = new GlideRecord('sys_user');
var reqby = chg.getValue('requested_by');
var cond = user.get('name',reqby)

if (cond)
{
var userEmail = user.getValue('email');
for (var i = 0; i < groupNames.length; i++) {
var group = new GlideRecord('sys_user_group');
if (group.get('name', groupNames[i])) {
var groupHasUser = new GlideRecord('sys_user_grmember');
groupHasUser.addQuery('user',user.getValue('user_name'));
groupHasUser.addQuery('group', group.getValue('sys_id'));
groupHasUser.query();
if (groupHasUser.next()) {
gs.log (" Vignesha priya log checking" + userEmail);
}
else
{
gs.log (" Vignesha priya log checking - user is not part of the group");
}
}
}
}
gs.log (" Vignesha priya log checking - User is not in user table");
},

type: 'checking_user_is_part_of_specific_Group'
};

This is my script include. I need to check output of the script include. I am using gs.log(). May I know if the format is correct. Where can I check log statement. I am not finding it under System logs. I call this in change approval decision.

VigneshaPriya_0-1684142084705.png

I try to check the condition by creating a change request with the highlighted condition. 

5 REPLIES 5

Manmohan K
Tera Sage

Hi @Vignesha Priya ,

 

 log(String message, String source)

Logs a message to the system log and saves it to the syslog table.

Parameters:

 

  • String message - message to log, for the log's Message field.
  • String source - (optional) the source of the message, for the log's Source field.

All the logs go in syslog table

You can add source which will help you easily find the log statement in sys_log table

i.e. gs.log (" Vignesha priya log checking - user is not part of the group","Vignesha");

 

Now you can filter syslog table with source=Vignesha and find your log statements output

Amit Gujarathi
Giga Sage
Giga Sage

HI @Vignesha Priya ,
I trust you are doing great.

The format of your gs.log() statements appears to be correct. However, the logs generated using gs.log() are not stored in the System logs by default. They are stored in the "System Log" table (syslog) in ServiceNow. To view the log statements, you can follow these steps:

  1. Open the "System Log" table by navigating to "System Diagnostics" > "Logs" > "System Log".
  2. Apply any necessary filters to locate the log statements you are interested in. You can filter by the log message or the user who executed the script.
  3. Once you find the relevant log entries, you can click on them to view the details of the log message.

To check the output of your script include, you can add gs.log() statements as you have done. Make sure that the script include is being called correctly from your change approval decision script. Once the script is executed, the log statements should be captured in the "System Log" table, and you can view them following the steps outlined above.


Was this answer helpful?


Please consider marking it correct or helpful.


Your feedback helps us improve!


Thank you!


Regards,


Amit Gujrathi



KB18
Tera Guru
Tera Guru

Dear @Vignesha Priya ,

 

Please use this script in the condition to check user is member of the Group. If needed please modify the script as per requirement.

 

How to select only users of a specific group into a reference field - Support and Troubleshooting (s...

 

javascript&colon;'sys_idIN'+getIDs(current.group);

function getIDs(grp){
var m=GlideUserGroup.getMembers(grp);
var ids='';
while (m.next()){
ids+= (m.user+',');
}
return ids;
}

 

Your syntax is correct, 

GS.LOG("Give the string value " + field value to check, "Scope Value like4444");

go to sys log table and give scope==4444, it will give all the logs.

 

Note : gs.log will not work in the global scope. Use gs.info with same syntax mentioned above.

Please hit the thumb Icon and mark as correct in case I help you with your query!!!
- Kailas

GS.LOG("Give the string value " + field value to check, "Scope Value like4444");

May I know GS.LOG is gs.log ,correct?

Please clarify Scope Value like 4444 inside quotes

and you are searching scope==4444. May I know where are we searching this..is it under source or message. Cant we not search like this- Scope Value like 4444. I mean same text inside quotes