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)

Cloning Records in Plugin

(0) ShareShare
ReportReport
Posted on by

Hello All,

I have requirement 

Opportunity -> Opportunity Product (1:N)

In Opportunity we have Opportunity Product sub-grid.

But once Currency in Opportunity is set and Opportunity Products are added then Currency of Opportunity cannot be changed (Agree -> By design we cannot modify Opportunity currency since its associated records are in previously set currency)

Actual Requirement :

In order to change the currency we need to delete all Opportunity Product records associated with the Opportunity and then change currency of the Opportunity.(So its very cumbersome)

We need to Clone records of Opportunity Products with updated currency at once when currency is changed.(and of course delete previously created Opportunity Product records with old currency)

Please note that in the error pops-up as shown below in In-Operation stage of Event execution pipeline as this CRM side validation.(My assumption). Thus we cannot register any Plugin in Post-Operation stage.

6644.Error.png

Please help me out how to implement this scenario.

*This post is locked for comments

I have the same question (0)
  • Verified answer
    Aric Levin - MVP Profile Picture
    30,190 Moderator on at

    One thing that you might be able to do here is create an action (let's say it's called Change Currency).

    You pass the new currency to the action via JavaScript which executes the Action code.

    The action code would then clone the Product records with the new currency, and after they are created, delete/deactivate the old ones.

    Once the old records are removed, you should probably be able to modify the Currency via the Plugin (Action) code.

    Hope this helps.

  • Suggested answer
    khoait Profile Picture
    450 on at

    Hi. I would try following approaches:

    1. Use custom action

    2. Use Plugin

    • Create a plugin on Pre-validation Update message for Opportunity entity, filter for Currency attribute change.
    • Create a Pre Entity Image, include attributes. This image will be used to get the "before-update" Currency.
    • Get "before-update" record and "updating" record:
    Entity preImage = (Entity)context.PreEntityImages["PreImage"];
    Entity entity = (Entity)context.InputParameters["Target"];
    
    EntityReference oldCurrency = (EntityReference)preImage["transactioncurrencyid"];
    EntityReference newCurrency = (EntityReference)entity["transactioncurrencyid"];
    • Apply more logic as needed, and use SDK messages to create new Opportunity with fields copied from the current one, delete/deactivate the current one
    • Then you'll want to cancel the Update event, and show a message that a new Opportunity has been created. 
    throw new InvalidPluginExecutionException("A new Opportunity has been cloned");


    Each approach has good and bad things, they depend on your requirements.

    Hope it helps.

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