CRMscript: Ticket.sendMessages function - How to build a correct StringMatrix?
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
All Replies (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
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
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.