Solved

CRM 2011 - Calculating Commisions

Posted on 2011-09-21
13
1,141 Views
Last Modified: 2012-05-12
Hi

Is there a built in way to create salesperson commissions in CRM 2011?  I have looked through the software but do not see one.

If not, can it be done using javascript or a workflow?

Thanks
0
Comment
Question by:apollo7
  • 7
  • 6
13 Comments
 
LVL 27

Expert Comment

by:Chinmay Patel
ID: 36573851
Hi apollo7,

There is no built in way to do so. However you can do it by JavaScript or Workflow but will have to see exact requirement for the same.

Regards,
Chinmay.
0
 
LVL 1

Author Comment

by:apollo7
ID: 36575985
I am trying to get used to the formatting of script in CRM 2011.  I have defined a function and populated it with script.  The first script works (var controlsLength) and the second one (var commrate) does not.

Any suggestions?

Thanks
function getControlCount() 
{

 var controlsLength = Xrm.Page.ui.controls.getLength();
 alert("This form has " + controlsLength + " controls on it.");

 var commrate = Xrm.Page.ui.controls.get("name");
 alert("This form has " + commrate + " on it.");
 
}

Open in new window

0
 
LVL 27

Expert Comment

by:Chinmay Patel
ID: 36578288
Hmmmm What exactly happens with the second script? you get an error?
0
 
LVL 1

Author Comment

by:apollo7
ID: 36579537
Chinmay,
Thanks for the response.  I have gotten past the second script issue and now have a different issue.  What I am trying to do, btw, is to take a commission rate (from an invoice form), mulitiply it by the totalamount field and come up with a total commission amount (also on the invoice form).

The code below works except for the final calculation.  No error, it justs not return anything when from the alert - alert(TotalComm);

I appreciate your help.

function AlertRateField() {
    var MainRate = Xrm.Page.data.entity.attributes.get("new_commissionrate").getValue();
    alert(MainRate);

    var MainComm = Xrm.Page.data.entity.attributes.get("new_commissiontotal").getValue();
    alert(MainComm);

    var MainTotal = Xrm.Page.data.entity.attributes.get("totalamount").getValue();
    alert(MainTotal);

    var TotalComm = MainTotal * MainRate;
    alert(TotalComm);

}

Open in new window

0
 
LVL 27

Expert Comment

by:Chinmay Patel
ID: 36579573
Hi apollo7,

Do you get a message box? or you dont get the message box?
also try

var TotalComm = parseInt(MainTotal) * parseInt(MainRate);

Open in new window



instead of

var TotalComm = MainTotal * MainRate;

Open in new window



Regards,
Chinmay.
0
 
LVL 1

Author Comment

by:apollo7
ID: 36580046
Ok, I have all the get statements working and all the alerts return the correct values.

Now I am trying to set the value of new_commissiontotal (var MainComm) to the value of the  TotalComm.variable.  

Any suggestions on this?  I have tried serveral set options and keep getting the "value is null" errors.

The code that works is below.

Thanks
function AlertRateField() {
    
    var MainRate = Xrm.Page.data.entity.attributes.get("new_commissionrate").getValue();
    alert(MainRate);

    var MainComm = Xrm.Page.data.entity.attributes.get("new_commissiontotal").getValue();
    alert(MainComm);

    var MainTotal = Xrm.Page.data.entity.attributes.get("totalamount").getValue();
    alert(MainTotal);

    var TotalComm = MainTotal * MainRate;
    alert(TotalComm);
    
}

Open in new window

0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 27

Accepted Solution

by:
Chinmay Patel earned 500 total points
ID: 36580074
Did you try :

Xrm.Page.getAttribute("commissiontotal").setValue(TotalComm);
0
 
LVL 1

Author Comment

by:apollo7
ID: 36580557
Chinmay

Tried the code you have above and also the following.  In both cases, I get the error:
Object doesn't support property or method "getAttribute"


function AlertRateField() {
    
    var MainRate = Xrm.Page.data.entity.attributes.get("new_commissionrate").getValue();
    alert(MainRate);

    var MainComm = Xrm.Page.data.entity.attributes.get("new_commissiontotal").getValue();
    alert(MainComm);

    var MainTotal = Xrm.Page.data.entity.attributes.get("totalamount").getValue();
    alert(MainTotal);

    var TotalComm = MainTotal * MainRate;
    alert(TotalComm);
    
     Xrm.Page.data.entity.attributes.getAttribute("new_commissiontotal").setValue(TotalComm); 
}

Open in new window

error1.jpg
0
 
LVL 27

Expert Comment

by:Chinmay Patel
ID: 36581110
Hmmmm Can I look at the script? I mean in action? TeamViewer?
0
 
LVL 1

Author Comment

by:apollo7
ID: 36581866
Chinmay,

I kept changing it and got it to work!  

Thanks very much for your help :)
0
 
LVL 27

Expert Comment

by:Chinmay Patel
ID: 36583139
Hi apollo7,

Do post the correct script and as usual if it was you who figured it out... points should go to your post.

Regards,
Chinmay.
0
 
LVL 1

Author Comment

by:apollo7
ID: 36583649
Chinmay,

I will post the script that works - it is a variation on one of  your posts, however, I understand what you are saying.  I do think you should get the points but lets decide after I post the script.

Thanks
0
 
LVL 1

Author Comment

by:apollo7
ID: 36583723
Chinmay,

This is the script that worked for me:
   Xrm.Page.getAttribute("new_commissiontotal").setValue(TotalComm);

If you compare it to the script that you posted and I awarded the points to:
   Xrm.Page.getAttribute("commissiontotal").setValue(TotalComm);

you will see they are very close.  Also, when I said "I kept changing it and got it to work!", what I should have said was that I made a lot of changes that didnt help things and then I saw that I just needed to add "new_" to "commissiontotal".  After I made that change, it worked fine.

Thanks again for your help.
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now