Skip to main content
Dynamics 365 general forum
Answered

Opportunity close as won

editSubscribe (0) ShareShare
ReportReport
Posted on by 163

Hi everyone,

I am trying to create a flow using dataverse connector that would allow to achieve this use case: if an opportunity is closed as won, then in the opportunity close overlay the current value of contract start date and contract end date on the opportunity record to reflect on the opportunity close overlay but I can't figure how to pass the right value in the flow.

Any ideas/steps would be helpful.

Thanks

  • Community Member Profile Picture
    Community Member UG Leader on at
    RE: Opportunity close as won

    Hi Sol007,

    I recommend you to post a new thread. This will benefit others who have the same problem.

  • Sol007 Profile Picture
    Sol007 163 on at
    RE: Opportunity close as won

    Hi,  

    Hope you don't mind me reaching out for guidance on this. I am stuck on updating a POS field on Opportunity entity based off of a field on Lead BPF stage.

    Can you please suggest if using a flow can achieve this use scenario: if child opportunity status = active, all other subsequent fields are set to either No or empty and then update the Probability of Success field to either 0 or 10%?

    flow-step-action.jpg

  • Sol007 Profile Picture
    Sol007 163 on at
    RE: Opportunity close as won

    Thanks Steve Zhao, super helpful!

  • Verified answer
    Community Member Profile Picture
    Community Member UG Leader on at
    RE: Opportunity close as won

    Hi,

    You could try this JS script:

    function formOnLoad(executionContext){
    	var formContext = executionContext.getFormContext();
    	var opportunityId = formContext.getAttribute("opportunityid").getValue()[0].id;
    	var opportunitystatecode = formContext.getAttribute("opportunitystatecode").getValue();
    	//close as won
    	if(opportunitystatecode === 1){
    		formContext.getControl("new_contractstartdate").setDisabled(true);
    		formContext.getControl("new_contractenddate").setDisabled(true);
    		Xrm.WebApi.retrieveRecord("opportunity", opportunityId).then(
    			function success(result){
    				if(result != null && result['new_contractstartdate'] != null){
    					formContext.getAttribute("new_contractstartdate").setValue(new Date(result['new_contractstartdate']));
    				}
    				if(result != null && result['new_contractenddate'] != null){
    					formContext.getAttribute("new_contractenddate").setValue(new Date(result['new_contractenddate']));
    				}
    			}, 
    			function fail(error){
    				Xrm.Navigation.openAlertDialog({text:error.message});
    			}
    		);
    	}else{
    		formContext.getControl("new_contractstartdate").setVisible(false);
    		formContext.getControl("new_contractenddate").setVisible(false);
    	}
    }

    Edit Opportunity close form Doc:

    Enable customization of Opportunity Close form - Sales Enterprise | Microsoft Docs

    Customize the Opportunity Close form (Dynamics 365 Sales) | Microsoft Docs

    Result:

    pastedimage1634869157715v1.png

  • Sol007 Profile Picture
    Sol007 163 on at
    RE: Opportunity close as won

    Hi Steve Zhao,

    Many thanks for your time in sharing the flow steps.

    I appear to be still stuck and the only to way it seems to acheive this is to attach javascript on form load of the opportunity close as we have no close opportunity records created before and do not exist in database.

    Would you know of another workaround?

    Regards,

    Sol

  • Suggested answer
    Community Member Profile Picture
    Community Member UG Leader on at
    RE: Opportunity close as won

    Hi Sol007,

    Please follow this step:

    1. Set your trigger options like the below screenshot.(The flow would be triggered when the opportunity is closed as won)

    pastedimage1634694446597v1.png

    2. Get your Completed status opportunity close record related to this opportunity.(Opportunity has one to many relationships to Opportunity Close. When you close an opportunity, there is a record whose status in completed inserted into Opportunity Close. And other Opportunity Close records‘ status would be changed to canceled. In this step, I just get the newest inserted Opportunity Close record to sync contract start/end date. If you need to sync all records, please delete the condition "and statecode eq 1" in the Filter rows setting.)

    pastedimage1634694606381v2.png

    3. Sync contract start/end date.

    pastedimage1634695334645v3.png

    Note: select contract start/end date from your trigger not list rows.

    pastedimage1634695394073v4.png

    Result:

    Opportunity:

    pastedimage1634695426692v5.png

    Opportunity Close:

    pastedimage1634695441164v6.png

  • Sol007 Profile Picture
    Sol007 163 on at
    RE: Opportunity close as won

    Hi Steve Zhao,

    Thanks for your response.

    1. You create contract start date and contract end date both on Opportunity and Opportunity Close entity? - Yes, both fields are on Opportunity and Opportunity Close entity.

    2. When you  close your Opportunity as won, you need to sync contract start date and contract end date form Opportunity to Opportunity close? - Yes, that is the task I am trying to achieve and it should be the current value of either the contract start date and contract end date.

    I am pretty new to learning flow and really appreciate your guide!

    Regards,

    Sol

  • Suggested answer
    Community Member Profile Picture
    Community Member UG Leader on at
    RE: Opportunity close as won

    Hi Sol007,

    There are two things to confirm:

    1. You create contract start date and contract end date both on Opportunity and Opportunity Close entity?

    2. When you  close your Opportunity as won, you need to sync contract start date and contract end date form Opportunity to Opportunity close?

    And there are some question about your flow:

    1.Your demand is that sync contract start date and contract end date form Opportunity to Opportunity close when you close your Opportunity as won( If I didn't misunderstand), why your change type of your trigger in the first screenshot is Added or Modified? In my option, you just need to select Modified.

    2.In your second step(update a row), you passed opportunity's GUID to Row ID of Opportunity close entity. This is wrong. Row ID of Opportunity close entity is Opportunity close's GUID not opportunity's. Due to Opportunity entity and Opportunity close entity has one to many relationship, you could use List rows action to get all Opportunity close entity records by opportunity's GUID.

    Looking forward to your reply and I would provide the flow after that.

  • Sol007 Profile Picture
    Sol007 163 on at
    RE: Opportunity close as won

    Hi Steve Zhao,

    Thanks for reaching out, please see below screen shots of what I did so far but get error (flow failed) and I am stuck on how to create a rule/set the contract start date and contract end date = default value as current date itself. Or if the contract start date is empty, then set default value as equal to created date?

    Scr.png

    Scr_5F00_i.png

    Any further guidance and steps to accomplish this would be appreciated.

    Thanks

    Sol

  • Community Member Profile Picture
    Community Member UG Leader on at
    RE: Opportunity close as won

    Hi Sol007,

    Please provide the screenshots of flow about what did you do by now and where are you stuck.

Helpful resources

Quick Links

What Motivates a Super User?

We know many of you visit the Dynamics 365 Community and Power Platform…

Demystifying Copilot with Sundar…

Industry experts answer burning questions directly from our amazing Community…

Enabling Copilot Case and Conversation…

Agents can easily recap an ongoing chat, transcribe a voice conversation…

Leaderboard

#1
Andre Arnaud de Calavon Profile Picture

Andre Arnaud de Cal... 283,030 Super User

#2
Martin Dráb Profile Picture

Martin Dráb 222,562 Super User

#3
nmaenpaa Profile Picture

nmaenpaa 101,138

Product updates

Dynamics 365 release plans