Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM forum
Answered

Timeline Activity Not Appearing after Changing Sender E-mail

Posted on by 24
Hello,

When replying mails from timeline activity:

I'm modifying the default sender adress to the queue entity for every E-Mail form using below JS. However, e-mails sent this way are not recorded in the timeline of the case.

How can I change this behaviour?

Thanks.
 
function setSender(executionContext, entityType, name, ID) {
    var formContext = executionContext.getFormContext();
    // Check if the script has already run
    if (sessionStorage.getItem(/setSenderExecuted/)) {
        return; // Exit the function if the script has already run
    }
    // Set the /From/ field
    var lookup = new Array();
    lookup[0] = new Object();
    lookup[0].id = ID; 
    lookup[0].name = name; 
    lookup[0].entityType = entityType;
    formContext.getAttribute(/from/).setValue(lookup);
    // Mark the script as executed
    sessionStorage.setItem(/setSenderExecuted/, /true/);
}
 
  • BK-17051419-0 Profile Picture
    BK-17051419-0 24 on at
    Timeline Activity Not Appearing after Changing Sender E-mail
    Sorry, I'm new to all Power Apps world. I call this function onLoad when a user clicks reply in timeline of a case. 

    This is my incomplete code.  I can't access parentactivity id on the e-mail form. it's not there?

    I think one of the mistakes lies in the line:

    var lookupObject = formContext.getAttribute("ticketnumber"); // Get the Lookup Object
     
    var formContext;
    function getLookupValue(executionContext) {
        formContext = executionContext.getFormContext(); // Get formContext
        var lookupObject = formContext.getAttribute("ticketnumber"); // Get the Lookup Object
        if (lookupObject != null) {
             console.log("lookupObject value is not null")
            var lookupObjectValues = lookupObject.getValue(); // Get the Lookup Value
            if (lookupObjectValues != null) {
                var RecordId = lookupObjectValues[0].id; // Get the Lookup id
                var RecordName = lookupObjectValues[0].name; // Get the Lookup Name
                var EntitySchemaName = lookupObjectValues[0].entityType; // Get the Lookup EntityName
                // Call setLookupValue with the retrieved values
                setLookupValue(executionContext, "regardingobjectid", RecordId, RecordName, EntitySchemaName);
            }
        } else {
            console.log("lookupObject value is null")
        }
    }
    function setLookupValue(executionContext, regardingAttribute, RecordId, RecordName, EntitySchemaName) {
        if (regardingAttribute != null) {
            var lookupValue = new Array();
            lookupValue[0] = new Object();
            lookupValue[0].id = RecordId;
            lookupValue[0].name = RecordName;
            lookupValue[0].entityType = EntitySchemaName;
            formContext.getAttribute(regardingAttribute).setValue(lookupValue); // Set lookupValue from array
            console.log("Lookup value set for " + regardingAttribute);
        } else {
            console.log("Lookup value not set");
        }
    }
    // OnLoad function to initiate the process
    function onLoad(executionContext) {
        console.log("onLoad function called.");
        getLookupValue(executionContext);
    }
  • Suggested answer
    Leah Ju Profile Picture
    Leah Ju Microsoft Employee on at
    Timeline Activity Not Appearing after Changing Sender E-mail
    Hi,
     
    There is one lookup column in the email.
    --In replied emails, the Parent Activity Id column store the parent or initial email id.
    So you can retrieve parent email get regarding value through the column value .
  • BK-17051419-0 Profile Picture
    BK-17051419-0 24 on at
    Timeline Activity Not Appearing after Changing Sender E-mail
    I couldn't find a way to access ticketnumber and title from e-mail form so that I can set regardingobjectid. Could you also help with that?
  • Verified answer
    Leah Ju Profile Picture
    Leah Ju Microsoft Employee on at
    Timeline Activity Not Appearing after Changing Sender E-mail
    Hi,
    You need to set 'Regarding' column in the email through javascript.
    ‘Regarding’ column is also one special lookup, so you can also write code similar as 'From' column.
    --Changing attribute to regardingobjectid when set value.
    formContext.getAttribute('regardingobjectid').setValue(lookup);
    More details:

    I hope you can mark my answer verified if it answer your question! If you have any questions, please feel free to contact me.
    Regards,
    Leah
     

Helpful resources

Quick Links

Replay now available! Dynamics 365 Community Call (CRM Edition)

Catch up on the first D365 Community Call held on 7/10

Community Spotlight of the Month

Kudos to Saurav Dhyani!

Congratulations to the June Top 10 community leaders!

These stars go above and beyond . . .

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 288,584 Super User

#2
Martin Dráb Profile Picture

Martin Dráb 225,864 Super User

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans