Narsing1
Mega Sage

This Article helps you in getting the complete activity logs from a record that includes work notes & comments with a command. You can use this in different ways on tables that are extended to Task i.e. Incident, RITM etc.,

Sample Code:

var j = new GlideSPScriptable().getStream("incident", "<record sysid>");
for(var m = 0; m < j.entries.length; m ++) {
gs.print(j.entries[m].field_label + " - " + j.entries[m].value + " - Added By " + j.entries[m].login_name + " - On " + j.entries[m].sys_created_on.toString());   
}

Sample Result

Additional comments - Followup on my Incident- Added By David Miller - On 2020-12-12 07:11:27
Additional comments - When my ticket is going to be resolved - Added By David Miller - On 2020-12-12 07:11:14
Work notes - more information from security team- Added By System Administrator - On 2020-12-11 13:41:10

To see complete activity log

var j = new GlideSPScriptable().getStream("incident", "<record sysid>");
gs.print(JSON.stringify(j));

Please bookmark & mark it as helpful if it solves your issue.

Thanks,

Narsing

Comments
Narsing1
Mega Sage

In the same way, you can get the RITM Variables and its values like this.

var gr = new GlideRecord("sc_req_item");
gr.get("f45ffa072f6301102dab2aa62799b631");
var js = new GlideSPScriptable().getRecordVariables(gr);
gs.print(js);
Sample

[{
        "display_value": "Additional Comments",
        "name": "select_your_option",
        "visible_summary": true,
        "id": "234fb2872f6301102dab2aa62799b631",
        "label": "Select Your Option",
        "type": "5",
        "value": "ac",
        "visible_standalone": true,
        "visible_guide": true
    }, {
        "display_value": "asdf",
        "name": "business_justification",
        "visible_summary": true,
        "id": "a34fb2872f6301102dab2aa62799b631",
        "label": "Business Justification",
        "type": "2",
        "value": "asdf",
        "visible_standalone": true,
        "visible_guide": true
    }, {
        "display_value": "asdf",
        "name": "additional_comments",
        "visible_summary": true,
        "id": "2f4fb2872f6301102dab2aa62799b630",
        "label": "Additional Comments",
        "type": "2",
        "value": "asdf",
        "visible_standalone": true,
        "visible_guide": true
    }]
louissicko
Tera Contributor

Hey,

 

thank you for that snipped! I tried that in a scoped application I'm currently building, but I get the following error:


java.lang.NullPointerException: Cannot invoke "com.glide.service_portal.widget.SPScriptable.getStream(String, String)" because "this.fSPScriptable" is null

 

Do I need to setup some privilege, to access that class from an other scope than Global?

 

Thank you so much!

With kind regards

Louis

Narsing1
Mega Sage

Hi,

Can you ping me the code here.  getStream works on all tables extended to task.

 

Thanks,

Narsing

dhyey-patel
Tera Explorer

Any clue if there's a way to obtain history events like - Field changes, Relationship changes, etc.?

Narsing1
Mega Sage

@dhyey-patel - You may go with HistoryWalker API. Please go through with the below article

Go to the Article

 

Thanks,

Narsing

TKS57
Tera Contributor

Could the results of this script be appended to an email notification?

I'm looking for a solution whereby people without access to servicenow can see all the comments that have been recorded against a RITM, by way of email. At the moment they only see the individual comment when it's entered but what we'd like them to see is a building trail of the latest comment, plus all previous comments, in the same way that a user sees this when they look at their request from the Employee Centre portal if they have access.

 

Or is there a better way to achieve this?

Version history
Last update:
‎10-15-2021 11:36 PM
Updated by: