CRMscript: Ticket.sendMessages function - How to build a correct StringMatrix?

lock
push_pin
done
Beantwoord
6

Hi!

I am trying to send a mail from trigger and would like to use the built in function ticket.sendMessages

The documentation in that function lacks a complete example I think? 
I am struggling with creating a correct StringMatrix of the recipients.
It would be nice with an complete example actually showing how to create a stringMatrix and other parameters and code for actually using the sendMessages function.

Does anyone having an example

I have tried this:

==
String strSendMatrix ="To | Anders Larsson <anders.larsson@amesto.se>";
StringMatrix SendMatrix;
SendMatrix.addCell(strSendMatrix);
String MessagesId = m.getValue("messageId");

Bool SendTicketStatus = t.sendMessages(t.getValue("ticketId"),SendMatrix,true,MessagesId,-1,"TestHeader");
==
But geting : Index out of range exception

//Anders

15 okt 2024 | 08:10 a.m.

Alles Antwoorden (6)

Hello Anders, 

When using the StringMatrix you have to create it yourself, with rows and columns, yourself. 
This means that in this case the code would look like this:

#setLanguageLevel 4;
Integer ticketId = 67;
String messageId = "133";
Ticket t;
t.load(67);
StringMatrix matrix;
matrix.addRow();
matrix.addCell("To");
matrix.addCell("Anders Larsson 

Feel free to create an issue on docs for improving the StringMatrix-documentation :) 

//Eivind

15 okt 2024 | 08:51 a.m.
Thanks Eivind
Ah, I will try that!
Also this could need some improvement in documentation: regarding message.send functions.
https://docs.superoffice.com/en/automation/crmscript/reference/CRMScript.Native.Message.html

15 okt 2024 | 09:03 a.m.
Hi again, I managed to get an email sent but the email did not conatain the message passed as parameter.
Earlier in my trigger script I create a new a message. That is what I want to get included.
Not sure if your example code was complete?
Also the ticket was/is not updated with the mail/message sent?
If manually forwarding a message the ticket reflects that action.

--Code snippet
StringMatrix SendMatrix;
SendMatrix.addRow();
SendMatrix.addCell("To");
SendMatrix.addCell(strSendMatrixTo);

String MessagesId = m.getValue("messageId");
//Bool SendTicketStatus =
//t.sendMessages(strSubject,SendMatrix,false,MessagesId,-1,"Avvikelse mottagen och registrerad");
t.sendMessages(strSubject,SendMatrix,false,MessagesId,MessagesId.toInteger(),"TEST header");

t.save(); //spara ärendet - behöver det sparas igen?
---
Not sure on the parameters "messages", "msgId".
In documentation messages should be string containing one or more messageIds
what is then msgId? I have tested both -1 and the messageId that I try to Forward.

sendMessages(String subject, StringMatrix recipients, Bool fromCust, String messages, Integer msgId, String comment)

Is it possible to get the ticket updated with the sent / forwarded message?
Since this is a triggerscript it is harder to debug, trace is enabled and I can see it. But it is not possible to get into the trace it self.
Just spinning..
status of trace is: [cropped]
SO version is 10.3.3 Onprem
Any known issues with trace in that version?
//Anders



15 okt 2024 | 11:22 a.m.

Hello Anders, 

I'm a little confused about your usercase.. 

You say `Earlier in my trigger script I create a new a message. That is what I want to get included.`; do you use the Message class to do this? e.g. something like this:

Ticket t;
t.load(67);

User u = getActiveUser();

Message m;
m.setValue("ticketId", t.getValue("id"));
m.setValue("createdBy", u.getValue("id"));
m.setValue("author", u.getValue("username"));
m.setValue("type", "1");
m.setValue("slevel", "1");
m.setValue("body", "here is all the text i want to include in the message");
Integer messageId = m.save();
m.addHeader("To", "foo@bar.com");

This would mean you already have a message on the ticket that contains all the information you want to send.
In that case why dont you use m.send() to actually send it?
I'm not sure i understand why you need to use sendMessages() at all, as you already have done 99% of the work earlier in your code (?)

Vector to;
to.pushBack("foo@bar.com");
Vector cc;
Vector bcc;
m.send(to, cc, bcc);



And FYI, in "old" service, a message is set as forwarded in the UI if: 
1. It is of type internal
2. Has recipients



//Eivind








16 okt 2024 | 09:08 a.m.
Hi Eivind! Thanks for the information.
The usercase is that we via the triggerscript process all incoming form registration/submissions (ordinary scripts did not work when implemented)
See this thread: https://community.superoffice.com/en/technical/forums/api-forums/service-crmscript/processing-form-by-crm-script/
And yes I create a new "slimmed" down message from the auto created incoming form replays.
This is what I want to send 1 or in some cases 2 recipients.
I will investigate m.send function (that was on my fallback scenario)
I was just starting out with ticket.SendMessages() since the documentation stated that it would replicated the forwarding functionallity in the GUI. And that was what I wanted I thought :-)
Note: That ticket.SendMessages() only takes the text version of the ticket eg body not htmlBody, would be nice if we could choose if body or htmlBody should be sent eg forwarded. I can see users case where I want to use that functionality to send one or more message as summery etc but in html not plain text.

//Anders
21 okt 2024 | 02:00 p.m.

Hi,
Just a sidenote related to ticket.SendMessages, this actually was used in previous version of Forward messages in CS (still accessible from Batch operation), and one of the less optimal sideeffects was the lack of actually being able to visually see what was forwarded. So suggest using what Eivind points out with message.send() or using Email class. 

 

22 okt 2024 | 10:20 a.m.

Reply toevoegen