How to attach data in Email and Chat interactions Workspace Desktop Edition

Hello, I´m tried to attach data to Email and Chat interactions when interaction doesn´t come with attached data en Case part with simple code:

                object caseObject;
                if (contextDictionary.TryGetValue("Case", out caseObject))
                {
                  
                    ICase caseInx = caseObject as ICase;
                   caseInx.MainInteraction.SetAttachedData("LastName", LN);

But doesn´t work. There is any way to send this information like part of data interaction. In interaction voice is working different:

voiceService.SetAttachedData(caseInx.MainInteraction.EntrepriseInteractionCurrent, “NumPerson”, nump);

This code work fine to voice interactions

Thanks for your help!!!

In which command do you try to get the interaction object?

I´m not using this sentence inside command, I´m trying execute inside Extended View button click event, when I get data from external web service.

public partial class MySampleView : UserControl, IMySampleView
{
//here container definition
readonly IObjectContainer container;
string ape=“S/N”;

private void GetData_Click(object sender, RoutedEventArgs e)
{
IAgent myAgent = container.Resolve();
IEnterpriseServiceProvider enterpriseService = myAgent.EntrepriseService;
IDictionary<string, object> contextDictionary = (Context as IDictionary<string, object>);
//IMediaVoice
IVoiceService voiceService = enterpriseService.Resolve(“voiceService”);
IChatService chatService = enterpriseService.Resolve(“chatService”);
IEmailService emailService = enterpriseService.Resolve(“emailService”);
object caseObject;
if (contextDictionary.TryGetValue(“Case”, out caseObject))
{

                    ICase caseInx = caseObject as ICase;

                    var tipo = caseInx.MainInteraction.Type;

                if (Dat.ape.ToString() != null)
                {
                  
                    ape = Dat.ape.ToString();
                }

                     if (tipo.ToString() == "InteractionEmail" || tipo.ToString() == "InteractionInboundEmail")
                    {

                        caseInx.MainInteraction.SetAttachedData("LastName", ape);
                      }
    }

Use InteractionManager interface to get an interaction object on which you can set the attached data