locked
CRM 2011 - Opportunity Close Entity Using SDK RRS feed

  • Question

  • Hi Forum,

    I am working on a project where I am merging 2 CRM systems (both 2011 on premise). I am using SSIS to get source system data in form of sql queries and then using SDK to create records in destination system.

    I am facing an issue while creating Opportunity records where status is closed (either won or lost).

    I have successfully created opportunity and set the status won or lost according to the source system but not able to copy opportunity close form information like Actual Close date, Actual Value etc...though it is populating "Subject" field which I can see in the opportunity "Close Activities" view.

    Below is my code. Would someone please check to find any obvious mistake I  have made. There is no error and when I debug I can see the values populated in the object attributes list but upon creating nothing is populated except subject. I have trim down code for better visibility and have put some inline comment.

    		
    		// creating Opportunity
    		 try
            {
               Guid OppID = service.Create(CreateOpp);
    		   SetOpportunityStatusWon(OppID, SourceRecord)  // Source Record is a single record from source query in SSIS package
    		   
    		}
    		
        public void SetOpportunityStatusWon(Guid opportunityId, Input0Buffer SourceRecord)
        {
            WinOpportunityRequest Wonreq = new WinOpportunityRequest();
    		
            Entity opportunityClose = new Entity("opportunityclose");
    		
            //Refering opportunity
    		opportunityClose["opportunityid"] =  new EntityReference("opportunity", opportunityId));
    		
            // Adding Actual Value,Actualclose date and subject
    		if (!SourceRecord.actualclosedate_IsNull)
            {
                opportunityClose["actualclosedate"] =  SourceRecord.actualclosedate; // not populating
            }
            if (!SourceRecord.actualvalue_IsNull)
            {
                opportunityClose["actualvalue"] = new Money(SourceRecord.actualvalue); // not populating
            }
            if (!SourceRecord.topic_IsNull)
            {
                opportunityClose["subject"] = SourceRecord.Topic.ToString()); //This is generating value
            }
    		
    		// Execute request wit won status
            Wonreq.OpportunityClose = opportunityClose;
            OptionSetValue Won = new OptionSetValue();
            Won.Value = 3;
            Wonreq.Status = Won;
            service.Execute(Wonreq);
    
        }

    Thanks for reading.

    Regards,

    H.Desai


    • Edited by H.Desai Thursday, November 5, 2015 10:49 PM
    Thursday, November 5, 2015 10:46 PM

Answers

  • actualvalue and actualclose date are attributes of the opportunity entity, not of opportunityclose. Both these attributes are ValidForCreate and ValidForUpdate on the opportunity, so you should just be able to set them on the opportunity before you execute WinOpportunity

    Opportunity does have actualend and actualvalue attributes, so you could try setting them on the opportunityclose


    Microsoft CRM MVP - http://mscrmuk.blogspot.com/ http://www.excitation.co.uk

    • Marked as answer by H.Desai Monday, November 23, 2015 10:04 PM
    Tuesday, November 17, 2015 11:21 AM
    Moderator

All replies

  • Hi,

    I did a quick check, on a CRM 2013 though, but it seems that the date and value attributes aren't set, weird.

    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

    Friday, November 6, 2015 8:54 AM
  • Hi Rickard,

    Thanks for testing this out for me. This is indeed weird unless I am missing something obvious.  I don't think there is any fundamental difference between 2 version regarding this functionality and I expect same behaviour in CRM 2011 and 2013.

    Is there anyone out there who has closed the opportunity programmatically and created Opportunity Close entity record (Activity) with custom values.

    Regards,

    H.Desai


    • Edited by H.Desai Wednesday, November 11, 2015 3:11 AM
    Wednesday, November 11, 2015 3:10 AM
  • Hi,

    Anyone out there who have created opportunity close record programmatically and populated actual close date and actual value though SDK?

    Regards,

    H.Desai

    Monday, November 16, 2015 9:07 PM
  • actualvalue and actualclose date are attributes of the opportunity entity, not of opportunityclose. Both these attributes are ValidForCreate and ValidForUpdate on the opportunity, so you should just be able to set them on the opportunity before you execute WinOpportunity

    Opportunity does have actualend and actualvalue attributes, so you could try setting them on the opportunityclose


    Microsoft CRM MVP - http://mscrmuk.blogspot.com/ http://www.excitation.co.uk

    • Marked as answer by H.Desai Monday, November 23, 2015 10:04 PM
    Tuesday, November 17, 2015 11:21 AM
    Moderator