locked
I got this Error: resource not found for the segment 'emailSet' RRS feed

  • Question

  • My Code is:

    function createREST()
    {
        var createEmail= {};
    createEmail.RegardingObjectId= { id: "CA6A23C2-14A8-47EF-BAA8-8AA05AEFFDFA" , logicalName: "email", type: "EntityReference" };

        SDK.REST.createRecord(
             createEmail,
             "email",
             function (createEmail) {
             },
             function errorHandler(error)
             {
                 alert(error.message);
             }
           );
    }

    Wednesday, March 16, 2016 7:25 AM

All replies

  • Hi,

    It's been a while since  had a run at doing creates with the REST interface but there are a few things I wonder about in your code. One is the 'type: "EntityReference"' part which I don't remember using and the next is the "email" in the create call which I think should be "Email" (capital E), you are getting an error saying "emailSet" and in all the REST-stuff the entity names are Pascal cased, at least for the OOB entites, it's all based on the Schema name that can be found in the customization part in CRM.

    You can find some examples here: https://msdn.microsoft.com/en-us/library/gg334427%28v=crm.7%29.aspx.

    Hope it helps.


    Rickard Norström Developer CRM-Konsulterna
    http://www.crmkonsulterna.se
    Swedish Dynamics CRM Forum: http://www.crmforum.se
    My Blog: http://rickardnorstrom.blogspot.se

    Wednesday, March 16, 2016 7:57 AM
  • Hi Rickard , Thank you for your response. I am currently looking to Create an Email record using Javascript for CRM 2015. Any ideas are suggestions welcome. I am stuck with this issue for almost a week,
    Wednesday, March 16, 2016 9:00 AM
  • Hi,

    What happens if you change the code to something like:

    function createREST()
    {
        var createEmail= {};
    createEmail.Subject= "test";

        SDK.REST.createRecord(
             createEmail,
             "Email",
             function (createEmail) {
             },
             function errorHandler(error)
             {
                 alert(error.message);
             }
           );
    }

    This will create an email with the subject "test", and if that works you can continue from there. This is how I usually start, doing something very simple, entityreferences doesn't count as very simple btw :)

    Hope it helps.


    Rickard Norström Developer CRM-Konsulterna
    http://www.crmkonsulterna.se
    Swedish Dynamics CRM Forum: http://www.crmforum.se
    My Blog: http://rickardnorstrom.blogspot.se

    Wednesday, March 16, 2016 9:11 AM
  • Thank you. New email record with Subject 'test' has been created. If I include the fields such as From and To its shows error as "Microsoft.Crm.Sdk.Data.Services.Email is not valid".

    Code is :

    function createREST()
    {
        var createEmail= {};
    createEmail.Subject= "Email 1";
    createEmail.From="abc@gmail.com";
    createEmail.To="ccc@msdn.net";

        SDK.REST.createRecord(
             createEmail,
             "Email",
             function (createEmail) {
             },
             function errorHandler(error)
             {
                 alert(error.message);
             }
           );
    }

    Is it the right way to include the fields ?

    Wednesday, March 16, 2016 9:58 AM
  • Well, yes and no... The to and from fields are slightly worse to work with since they are of entitycollection of activityparty type. It's a bit of headache to get those working, and doing it with REST isn't easier. I don't have any quick reference that I know will work, this is a start: http://neilparkhurst.com/2015/10/22/javascript-set-activity-party/

    You also have a property called "addressused" (or something similar) that you might be able to set without using an existing contact/account/user/whatever.

    Not a complete solution but perhaps a nudge in the right direction. Do you need to create the email with js btw?

    Regards


    Rickard Norström Developer CRM-Konsulterna
    http://www.crmkonsulterna.se
    Swedish Dynamics CRM Forum: http://www.crmforum.se
    My Blog: http://rickardnorstrom.blogspot.se

    Wednesday, March 16, 2016 10:16 AM
  • Thank you.

    Yes.I need to create an email record using JS.

    Wednesday, March 16, 2016 10:21 AM
  • You may not be able to set the activityparty field via REST.  I know I could not via the querystring, so instead I passed my from/to into a custom field and then parsed it out onLoad.  Depending on your situation, you could do the parsing in JavaScript, or a plugin.  Here's what it looks like in my onLoad function:

    var qsParams = Xrm.Page.getAttribute("ss_qsparams").getValue();
    
    // check to see if a value was passed in for the activity party(s)
    if (qsParams != null) {
    
    	var allParties = [];
    	var splitObjs = qsParams.split(";");
    	for (var p = 0; p < splitObjs.length; p++) {
    		var regObj = splitObjs[p].split("|");
    		if (regObj.length > 0) {
    			allParties.push({
    				entityType: regObj[0],
    				name: regObj[1],
    				id: regObj[2]
    			});
    		}
    	}
    
    	if (allParties.length == 1) {
    
    		Xrm.Page.getAttribute("to").setValue(allParties);
    	} else if (allParties.length > 1) {
    
    		Xrm.Page.getAttribute("cc").setValue(allParties);
    	}
    }

    Wednesday, March 16, 2016 12:18 PM
  • Custom Field you mean "To" and "From" fields right ? so I need to call the js function in "To" and "From" fields.
    Thursday, March 17, 2016 6:01 AM