Getting requested item activity steam in scoped application

ck_kannan
Tera Expert

Got a question related to requested item.    For an API we need to get the comments added into the sc_req_item  and display as a  status.

When we add comment to sc_req_table   all comments goes to activity stream. I am able to use below code   global scope (As a background script) to get activity stream and display it.

                var stream = new GlideSPScriptable().getStream('sc_req_item', <sysId of ritm>);

                a =  JSON.stringify(stream, null, '\t');

                activities = JSON.parse(a);

                for( i = 0 ; i < activities.entries.length; i++ ){

                            gs.print(activities.entries[i].sys_created_on  + "  " +  activities.entries[i].value);

                }

 

 

However when I move the code to scoped application I get below error

 

     "The server could not process the request. Error java.lang.RuntimeException: failed to coerce com.glide.script.fencing.ScopedGlideElement to desired type java.lang.String"

 

I changed to 'new global.GlideSPScriptable().getStream ' Now get error.

               "The server could not process the request. Error java.lang.SecurityException: Invalid object in scoped script:[JavaClass com.glide.service_portal.widget.SPScriptable]"

 

Question is how to query activity stream from a scoped application.   The script is running as Scriptable Rest API.

 

Thanks

Kannan

1 ACCEPTED SOLUTION

ck_kannan
Tera Expert

Thanks to Chuck I was able to answer this

 

https://www.servicenow.com/community/developer-forum/differences-between-getjournalentry-1-and-getjo...

 

so used below code

 

var gr = new GlideRecord("sc_req_item");

gr.addQuery('number','RITMy4999447');

gr.query();

msg=""

while (gr.next()){

  gs.debug( gr.comments.getJournalEntry(-1));

}

 

 

 

View solution in original post

1 REPLY 1

ck_kannan
Tera Expert

Thanks to Chuck I was able to answer this

 

https://www.servicenow.com/community/developer-forum/differences-between-getjournalentry-1-and-getjo...

 

so used below code

 

var gr = new GlideRecord("sc_req_item");

gr.addQuery('number','RITMy4999447');

gr.query();

msg=""

while (gr.next()){

  gs.debug( gr.comments.getJournalEntry(-1));

}