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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Custom CodeActivity - update a quotedetail line with quote information

(0) ShareShare
ReportReport
Posted on by

I am trying to achieve the following;

A user updates a specific Product line in a quote, after this has been done a second Product line (if it exists) should be updated with some values. 

To achieve this I have created a Workflow in my Dynamics environment; the workflow targets the quotedetail entity and gets triggered when the quantity of an existing product changes and the product is a product A. 

If the above condition is true then my custom workflow/CodeActivity (created in C#) gets activated. 

My idea was to retrieve the ID of the quote in which the quotedetail is being changed and then retrieve all the related quotedetail records and update the right one. I can't retrieve the ID of the quotedetail itself because the record being changed in the quotedetail is not the record which needs to be updated in code. 

To achieve the above I have set it up as follows:

[Input("QuoteID")]
[ReferenceTarget("quote")]

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

protected override void Execute(CodeActivityContext executionContext)
{
//Create the context
            IWorkflowContext context = executionContext.GetExtension<IWorkflowContext>();
            IOrganizationServiceFactory serviceFactory = executionContext.GetExtension<IOrganizationServiceFactory>();
            IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);

Entity regQuote = service.Retrieve("quote", context.PrimaryEntityId, new ColumnSet(new string[] { "name", "ownerid" }));
            string quoteName = (string)regQuote.Attributes["name"];

}


If I am not mistaken, a quotedetail is linked with a quote based on the name of the quote (not sure)? Though the field name in quotedetail is called quoteid, while the value of it is a quote name, which is a bit confusing since you would assume it targets the quoteid of the quote entity and not it's name.

When above code is executed I get the following error; 

quote With Id = 67ea974c-6449-e811-a831-000d3ab4b197 Does Not Exist


I suspect that the (input) value, in the workflow of dynamics (my custom workflow) is wrong. It retrieves / uses the quote of the quotedetail record as input of my custom codeactivity;

Property name: QuoteID 

Data type: lookup

Required: Optional

Value: {Quote(Quotedetail)} 

The above uses quotedetail as the entity (as mentioned earlier). 

The question is, how can I retrieve the right ID which connects the quote to the linked quotedetail records using the quotedetail as target entity in my Dynamics workflow, and which field is that in the quote entity?

*This post is locked for comments

I have the same question (0)
  • Verified answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at

    Hello,

    Try something like

    Entity regQuote = service.Retrieve("quote", SourceQuoteID.Get(executionContext).Id, new ColumnSet(new string[] { "name", "ownerid" }));

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
ScottDurow Profile Picture

ScottDurow 2

#2
GJones Profile Picture

GJones 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans