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)

Update a field within Order Product

(0) ShareShare
ReportReport
Posted on by

Hello!

I am trying to take a calculated field value (with many variables) within Order Products and copy the value into another simple field within the same Order Product, that can be used in a roll-up for the Order entity.

What I am trying to do is calculate a commission value for each product, based on a custom salesperson field (user lookup) where users are assigned a custom field of commission level, then roll that value up to the order as a total commission amount for the order.  A calculated field cannot be rolled-up, so my solution was to copy the calculated value into a simple text field, then sum them in the order, but I can't figure out a way to copy the value.

I am willing to try JavaScript but am not experienced in this and would need step by step, detailed instructions.

Any suggestions would be helpful.

Thanks!

*This post is locked for comments

I have the same question (0)
  • necsa Profile Picture
    3,455 on at

    Hi Sal_SKoontz,

    please can you add a screenshot of product and give type of commision level field.

  • Community Member Profile Picture
    on at

    necsa,

    Here is a screen shot of an order product, I apologize for the size.  The commission level type in the user is a picklist.

    Is there something in particular you are looking for?

    Thanks!

     

    Screen-Shot-2016_2D00_03_2D00_14-at-9.14.46-AM.png

  • necsa Profile Picture
    3,455 on at

    Hi Sal_SKoontz;

    Please give me more detail ore confirm my below questions to bre sure that i understand your problem exactly.

    1. Commision level field is on the sales person form.
    2. How is the definition of commission level? ist procential ?
    3. You want calculate each product commission belong the sales persons commission level
    4. Then you want to roll up total amount of commision as depent of sales person or generally?

    please let me know, am i understand your problem correct?

  • Community Member Profile Picture
    on at

    Necdet,

    1. Yes

    2. Commission level is a picklist: Rookie, professional, expert that is used to calculate a total within the "Product Commission" field.  for example, if the salesperson is a rookie, the calculation in would take the product amount X .04, if professional product amount X .05, etc.

    3. Yes, within the particular order (order Product)

    4. Yes, for the order as a whole based on the salesperson who sold that order.

  • Suggested answer
    Community Member Profile Picture
    on at

    hi

    1) use workflow

    www.magenium.com/.../Aggregates.aspx

    www.powerobjects.com/.../how-to-roll-up-values-from-child-records-to-parent-records-via-workflow-in-microsoft-dynamics-crm

    2)javascript, call form save

    var ov1 = Xrm.Page.data.entity.attributes.get("ov1").getValue();

    var ov2 = Xrm.Page.data.entity.attributes.get("ov2").getValue();

    var ov3 = Xrm.Page.data.entity.attributes.get("ov3").getValue();

    var ov4 = ov1+ov2+ov3

    Xrm.Page.getAttribute("ov4").setValue(ov3);

    Xrm.Page.getAttribute(attributeName).setSubmitMode("always");

    If my response is helps you, please mark as "Verified"

  • necsa Profile Picture
    3,455 on at

    Hi Sal_SKoontz,

    let we are working;

    first customize to your field name and value of commision on following javascript.

    Then upload in webresource then on your product form sales person field OnChange event.

    function commission()
    {
    	 var EntityName, EntityId, LookupFieldObject,comlev,extamount,comvalue;
    
        var Name = "";
    
        var resultXml;
    
        LookupFieldObject = Xrm.Page.data.entity.attributes.get('yourfieldnameofsalesperson');
    
        if (LookupFieldObject.getValue() != null) 
    	{
    
            EntityId = LookupFieldObject.getValue()[0].id;
    
    			EntityName = LookupFieldObject.getValue()[0].entityType;
    
    				resultXml = getDetails(EntityName, EntityId);
    
    					comlev=resultXml.attributes['yourfieldnameofcommisionlevel'].value;   
    
    		
    	}
    
      extamount=Xrm.Page.getAttribute("extendedamount").getValue();
      if(comlev!=null)
      {
    	  switch(comlev)
    	  {
    		  case "rookie":
    		  comvalue=extamount*(your commision value 0.4);
    		Xrm.Page.getAttribute("your product commision field name").setValue(comvalue);
    
    break;
    
    		  case "professional":
    			
    		  comvalue=extamount*(your commision value 0.5);
    		Xrm.Page.getAttribute("your product commision field name").setValue(comvalue);
    break;
    
    		  case "expert":
    		  
    		  comvalue=extamount*(your commision value 0.6);
    		Xrm.Page.getAttribute("your product commision field name").setValue(comvalue);
    break;
    		  
    	  }
    	  
    	  
      }
    	
    	
    function getDetails(EntityName, EntityId) {
    
        var cols = ["yourfieldnameofcommisionlevel"];
    
    		var retrievedResult = XrmServiceToolkit.Soap.Retrieve(EntityName, EntityId, cols);
    
        return retrievedResult;
    
    }	
    	
    
    }


    then save your Product Form and publish it. You can delete Product commision Simple field.

    Go to on Order Form.

    Add Currency field with fieldtype Rollup on Order Form and edit these field with below feature;

    Related Entity=Order Products(Order)

    filters If Commision fiels on Order Product contain data (this is optional if you want you can skip this stage)

    Aggregation:

    Select SUM of Amount like below screenshot

    save your form and publish.

    so easy enjoy itorderrollup.jpg

    Pc. Please ignore line number in code

  • Community Member Profile Picture
    on at

    This did not work.  I implemented just as you described and published all customizations.  When creating an order from a quote I have two issues:

    1. Salesperson did not carry over so I manually added that field but no amount was populated

    Screen-Shot-2016_2D00_03_2D00_15-at-10.13.05-AM.png

    2. When I manually added a second product to the order with the salesperson, an amount populated but not the correct amount.

    Screen-Shot-2016_2D00_03_2D00_15-at-10.13.05-AM.png

  • necsa Profile Picture
    3,455 on at

    Hi Sal_SKoontz,

    Please first check javascript, put alert and find which line the code breaking. I see in your screenshot you have bought product as existing product not manually. Take the way step by step and test every stage. I tested it is working perfect.

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