web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

How to copy data from closed quote during revision.

(0) ShareShare
ReportReport
Posted on by

When I press "revise" button, original quote is getting closed and a new quote, with state "draft" is being created. I'm getting redirected to newly created quote, however, one of my custom field is not getting copied. How to make it copy?

Right now, I created a plugin on pre-create Quote event, and the code is:

var parentContext = this.CrmServiceProvider.Context.ParentContext;
if (parentContext != null &&
    parentContext.PrimaryEntityId != null &&
    this.Entity.Contains(Quote.RevisionNumber_AttrName) &&
    (this.Entity.RevisionNumber ?? 0) > 0)
    {
        QuoteBO firstQuote = new QuoteBO(this.CrmServiceProvider, new EntityReference(Quote.EntityLogicalName, parentContext.PrimaryEntityId));
        if (firstQuote != null && firstQuote.Entity.ntw_PaymentTerms != null)
           {
// trying to copy from closed quote to new, draft quote this.Entity.ntw_PaymentTerms = firstQuote.Entity.ntw_PaymentTerms; } }


However, this does not work.parentContext.PrimaryEntityId is not null, but it's guid equals {0000-0000-0000-0000}.

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Bas van de Sande Profile Picture
    4,383 on at

    Hi Patryk,

    what you could do is write some fetchXML that will fetch the inactive record). Once you have a reference then you can copy the values you want.

    I hope this helps

    Bas

  • Mahendar Pal Profile Picture
    45,095 on at

    Hello,

    Did you try to register your plugin on revise event ??, you should get quoteid there

    www.patrickverbeeten.com/.../CRM-40-Plug-in-message-input-parameters

    Thanks

  • Suggested answer
    purwar purwar Profile Picture
    2,836 on at

    I am hoping below is helpfull for you, Ex: Get quote close description:

    namespace CRMGETQUOTE

    {

       using Entities;

       using Microsoft.Xrm.Sdk;

       using Microsoft.Xrm.Sdk.Query;

       using Microsoft.Xrm.Sdk.Workflow;

       using System;

       using System.Activities;

       using System.Linq;

       using System.ServiceModel;

       public sealed class GetQuoteClose : CodeActivity

       {

           /// <summary>

           /// Executes the workflow activity.

           /// </summary>

           /// <param name="executionContext">The execution context.</param>

           protected override void Execute(CodeActivityContext executionContext)

           {

               // Create the tracing service

               ITracingService tracingService = executionContext.GetExtension<ITracingService>();

               if (tracingService == null)

               {

                   throw new InvalidPluginExecutionException("Failed to retrieve tracing service.");

               }

               tracingService.Trace("Entered GetQuoteClose.Execute(), Activity Instance Id: {0}, Workflow Instance Id: {1}",

                   executionContext.ActivityInstanceId,

                   executionContext.WorkflowInstanceId);

               // Create the context

               IWorkflowContext context = executionContext.GetExtension<IWorkflowContext>();

               if (context == null)

               {

                   throw new InvalidPluginExecutionException("Failed to retrieve workflow context.");

               }

               tracingService.Trace("GetQuoteClose.Execute(), Correlation Id: {0}, Initiating User: {1}",

                   context.CorrelationId, context.InitiatingUserId);

               IOrganizationServiceFactory serviceFactory = executionContext.GetExtension<IOrganizationServiceFactory>();

               IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);

               try

               {

                   Quote quote = (Quote)service.Retrieve(QuoteToFind.Get(executionContext).LogicalName, QuoteToFind.Get(executionContext).Id, new ColumnSet(true));

                   EntityCollection closes = GetQuoteCloses(service, quote.Id);

                   if (closes.Entities.Count == 0)

                   {

                       QuoteCloseDesc.Set(executionContext, string.Empty);

                       return;

                   }

                   bool firstOrLast = FirstOrLast.Get(executionContext);

                   if (firstOrLast)

                   {

                       QuoteClose close = (QuoteClose)closes.Entities.First();

                       QuoteCloseDesc.Set(executionContext, close.Description);

                   }

                   else

                   {

                       QuoteClose close = (QuoteClose)closes.Entities.Last();

                       QuoteCloseDesc.Set(executionContext, close.Description);

                   }

               }

               catch (FaultException<OrganizationServiceFault> e)

               {

                   tracingService.Trace("Exception: {0}", e.ToString());

                   throw;

               }

               tracingService.Trace("Exiting GetQuoteClose.Execute(), Correlation Id: {0}", context.CorrelationId);

           }

           private EntityCollection GetQuoteCloses(IOrganizationService service, Guid id)

           {

               //Query for the quote closes

               QueryExpression query = new QueryExpression()

               {

                   EntityName = QuoteClose.EntityLogicalName,

                   ColumnSet = new ColumnSet(true),

                   LinkEntities =

                       {

                           new LinkEntity

                           {

                               LinkFromEntityName = QuoteClose.EntityLogicalName,

                               LinkFromAttributeName = "quoteid",

                               LinkToEntityName = Quote.EntityLogicalName,

                               LinkToAttributeName = "quoteid",

                               LinkCriteria = new FilterExpression

                               {

                                   FilterOperator = LogicalOperator.And,

                                   Conditions =

                                   {

                                       new ConditionExpression

                                       {

                                           AttributeName = "quoteid",

                                           Operator = ConditionOperator.Equal,

                                           Values = { id }

                                       }

                                   }

                               }

                           }

                       }

               };

               return service.RetrieveMultiple(query);

           }

           [RequiredArgument]

           [Input("Quote With Close")]

           [ReferenceTarget("quote")]

           public InArgument<EntityReference> QuoteToFind { get; set; }

           [RequiredArgument]

           [Input("Retrieve First (True) Or Last (False) Close")]

           public InArgument<bool> FirstOrLast { get; set; }

           [OutputAttribute("Quote Close")]

           public OutArgument<string> QuoteCloseDesc { get; set; }

       }

    }

  • Suggested answer
    Leandro Barbosa Profile Picture
    15 on at

    You can use Quote name as condition, when revised, it's created with the same name, the old status is Closed, and new one is Open.

    QueryExpression query = new QueryExpression("quote");
    query.ColumnSet = new ColumnSet(true);
    query.Criteria.AddCondition(new ConditionExpression("name", ConditionOperator.Equal, entity.GetAttributeValue<string>("name")));
    query.Criteria.AddCondition(new ConditionExpression("revisionnumber", ConditionOperator.Equal, entity.GetAttributeValue<int>("revisionnumber") - 1)); //last revision number
    query.Criteria.AddCondition(new ConditionExpression("statecode", ConditionOperator.Equal, 3)); //status Closed

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans