Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Using REST RetrieveRecord on activity entity to set recipient

(0) ShareShare
ReportReport
Posted on by 1,320

From an Email, I want to retrieve a custom lookup field ("new_manager") from the regardingobjectid (incident) and set the value as a recipient on the email.

Trying to run debugger and it seems it doesn't even fire the successcallback function "setManager".

Any help would be appreciated.

//SET MANAGER TO EMAIL RECIPIENT

function retrieveManager(regardingobjectId) {
    if(!Xrm.Page.getAttribute("regardingobjectid").getValue())
        return;

    var regardingobjectId = Xrm.Page.getAttribute("regardingobjectid").getValue()[0].id;
    var EntitySchemaName = "Incident";

    if (regardingobjectId.entityType == "incident") {
        SDK.REST.retrieveRecord(
        regardingobjectId,
        EntitySchemaName,
        "new_manager", null,
        setManager, errorHandler);
    }
}
function setManager(incident) {
debugger;
    var manager = incident.new_manager;
        if (manager != null) {
    var partlistData = new Array();
    partlistData[0] = new Object();
    partlistData[0].id = manager;
    partlistData[0].name = manager.name;
    partlistData[0].entityType = "systemuser";
    Xrm.Page.getAttribute("to").setValue(partlistData);
}
} 
function errorHandler(error) { 
alert(error.message); 
}


*This post is locked for comments

  • epark06 Profile Picture
    epark06 1,320 on at
    RE: Using REST RetrieveRecord on activity entity to set recipient

    [quote user="Andrew Butenko"]

    Try to use following:

       partlistData[0].id = manager.Id;

       partlistData[0].name = manager.Name;

       partlistData[0].entityType = "systemuser";

       Xrm.Page.getAttribute("to").setValue(partlistData);

    [/quote]

    This worked, thank you!

  • Suggested answer
    Dynamics_Alok Profile Picture
    Dynamics_Alok 1,746 on at
    RE: Using REST RetrieveRecord on activity entity to set recipient

    Hi ,

    We had similar issue and error message was like the same .Root cause for us was different version of Xrm Sdk registered in GAC.On retrieve if record or on update of record ,some server side code is executing and it is throwing error .Other reason may be related to SSL state stored in IE .Clear it and try to debug js again.

  • Verified answer
    a33ik Profile Picture
    a33ik 84,325 Most Valuable Professional on at
    RE: Using REST RetrieveRecord on activity entity to set recipient

    Try to use following:

       partlistData[0].id = manager.Id;

       partlistData[0].name = manager.Name;

       partlistData[0].entityType = "systemuser";

       Xrm.Page.getAttribute("to").setValue(partlistData);

  • epark06 Profile Picture
    epark06 1,320 on at
    RE: Using REST RetrieveRecord on activity entity to set recipient

    Ah spoke too soon....when I click Send Email I get this error:

    Unhandled Exception: System.ServiceModel.FaultException`1[[Microsoft.Xrm.Sdk.OrganizationServiceFault, Microsoft.Xrm.Sdk, Version=7.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]: System.FormatException: Microsoft Dynamics CRM has experienced an error. Reference number for administrators or support: #0F409AF0Detail: 
    <OrganizationServiceFault xmlns:i="www.w3.org/.../XMLSchema-instance" xmlns="schemas.microsoft.com/.../Contracts">
      <ErrorCode>-2147220970</ErrorCode>
      <ErrorDetails xmlns:d2p1="schemas.datacontract.org/.../System.Collections.Generic" />
      <Message>System.FormatException: Microsoft Dynamics CRM has experienced an error. Reference number for administrators or support: #0F409AF0</Message>
      <Timestamp>2018-04-26T02:37:59.7365512Z</Timestamp>
      <InnerFault i:nil="true" />
      <TraceText i:nil="true" />
    </OrganizationServiceFault>
    
    


  • epark06 Profile Picture
    epark06 1,320 on at
    RE: Using REST RetrieveRecord on activity entity to set recipient

    Ah, here we go, I added:

       var managername = incident.new_manager.Name;

       partlistData[0].name = managername;

    As always, thank you for your help!

  • epark06 Profile Picture
    epark06 1,320 on at
    RE: Using REST RetrieveRecord on activity entity to set recipient

    Thank you Andrew! Looks like I just need to adjust "partlistData[0].name = manager.name;" because it is returning an undefined value. Could you please help?

  • Verified answer
    a33ik Profile Picture
    a33ik 84,325 Most Valuable Professional on at
    RE: Using REST RetrieveRecord on activity entity to set recipient

    Hello,

    I believe your main issue that you firstly put id to regardingobjectId and after that you try to get entityType from it so your code fails... Try following:

    function retrieveManager(regardingobjectId) {

       if(!Xrm.Page.getAttribute("regardingobjectid").getValue())

           return;

       var regardingobjectId = Xrm.Page.getAttribute("regardingobjectid").getValue()[0];

       var EntitySchemaName = "Incident";

       if (regardingobjectId.entityType == "incident") {

           SDK.REST.retrieveRecord(

           regardingobjectId.id,

           EntitySchemaName,

           "new_manager", null,

           setManager, errorHandler);

       }

    }

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Congratulations 2024 Spotlight Honorees

Kudos to all of our 2024 community stars! 🎉

Meet the Top 10 leaders for December

Congratulations to our December super stars! 🥳

Start Your Super User Journey

Join the ranks of our community heros! 🦹

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,711 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,458 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans