Create sys_cs_message with GlideRecord form custom scope

David269
Tera Contributor

I'm trying to create a sys_cs_conversation with messages in a Script Include from a scoped application.

Creating the conversation worked fine with this:

var conversation = new GlideRecordSecure('sys_cs_conversation');
conversation.initialize();
conversation.setValue('device_type', 'CC Voice');
conversation.setValue('state', 'open');
var conversationId = conversation.insert();

 

Trying the same with sys_cs_message does not work:

var conversationMessage = new GlideRecordSecure('sys_cs_message');
conversationMessage.initialize();
conversationMessage.setValue('payload', transcriptMessage);
conversationMessage.setValue('conversation', conversationId);
var conversationMessageId = conversationMessage.insert();

I've created the necessary cross-scope priviliges from the source scope to the global target scope for all operations (read, create, write) and adapted application access (Can read, Can create, Can update) on the sys_cs_message table.

 

While it runs through in the script include it does not create a sys_cs_message record.

When executing the same lines in a background script in the same scope I receive this error:

Security restricted: Access to api 'setValue(sys_cs_message.payload)' from scope '[CUSTOM_SCOPE]' has been refused due to the api's cross-scope access policy. 
Security restricted: Access to api 'setValue(sys_cs_message.conversation)' from scope '[CUSTOM_SCOPE]' has been refused due to the api's cross-scope access policy. 
Security restricted: Create operation against 'sys_cs_message' from scope '[CUSTOM_SCOPE]' has been refused due to the table's cross-scope access policy

 

When executing this code in a background script in the global scope the record is created successfully.

I have also tried to create the message with:

var conversation = sn_connect.Conversation.get(conversationId);
conversation.sendMessage(transcriptMessage);

and 

var factory = new sn_cs.ConversationMessageFactory();
var message = factory.createTextMessage(conversationId, transcriptMessage);

but similar problems occur.

 

Is there a way to create a sys_cs_message without the use of the external Voice Interaction API?

https://www.servicenow.com/docs/bundle/xanadu-api-reference/page/integrate/inbound-rest/concept/voic...

3 REPLIES 3

SumanthDosapati
Mega Sage
Mega Sage

@David269 

Did you also check the restricted caller access privileges (sys_restricted_caller_access) table?

 

Regards,

Sumanth

Also try giving 'Execute API' access along with create.

 

Accept the solution and mark as helpful if it does, to benefit future readers.
Regards,
Sumanth

I struggled to create that.
Once I select my source scope I cannot select Global (AFAIK the scope of sys_cs_message) as my target and the same happens vice versa.