This project is read-only.

How do you update a "money" field easily like Jamie's xrmservicetoolkit?

May 3, 2013 at 11:05 AM
Essentially, I have some calculations carried out, then the record updates itself as the following shows:
//OPPORTUNITY REVENUE ----------------------------------------------------------

  var OpenCallsVar = Xrm.Page.getAttribute("new_openrecords").getValue();
  var RatePerMinute = Xrm.Page.getAttribute("new_rate").getValue();
  var OpportunityRevenueV = OpenCallsVar * RatePerMinute;
 //Toolkit to update the data

    //Entity we are updating
    entityName: "wse_timesheet",

    //Entity ID, taken from above
    id: ID,
    //Attribute, but Schema name not name of entity
    entity: {new_OpportunityRevenue: OpportunityRevenueV},
    async: false,

    successCallback: function (result) {


    errorCallback: function (error) {

        alert("There was an error when updating the contact record");


//END OPPORTUNITY REVENUE --------------------------------
I get an error saying the record wasn't updated. This is because my calculations are carried out and I'm returned a whole number, that I want to set as a "money" type in my new_OpportunityRevenue in field.

Using Jamie's toolkit the money type was easily set using the following code:

createContact.attributes["creditlimit"] = { value: 2, type: "Money" };

My question is, can it be done with this toolkit or should I use Jamie's toolkit for that. My preference as always is to use your toolkit because it's simple and very fast.

Thanks for any help.
May 3, 2013 at 2:32 PM
I don't think what you want can be done. I've been researching on this myself for weeks and I couldn't come up with a solution as the document is lacking. If you really need to do this then switch to the XRMServiceToolkit for that, it's more comprehensive and can do more than this toolkit.
May 3, 2013 at 4:17 PM
Edited May 3, 2013 at 5:04 PM
@syed263, check out the XrmSvcToolkitTest.aspx file distributed with the toolkit, it can handle Money field. Based on your code snippet, the right way to construct a Money field would be something like this.

entity: {"new_OpportunityRevenue": { Value: OpportunityRevenueV.toString() } },

@Andy, XrmServiceToolkit is bad in many ways, which I have tried to refrain from talking about that in public community. The only thing that we don't have in XrmSvcToolkit is the support of some SOAP messages (primarily CUD) using the SOAP endpoint. I was not able to commit time to implement this. If you are a developer, adding support of those SOAP messages is pretty straightforward.
May 3, 2013 at 4:26 PM
Thank you kindly Daniel. It worked perfectly.

I'm using CRM Online, so not sure how I would view the XrmSvcToolkitTest.aspx? Should I upload the files in a new solution in CRM?
May 3, 2013 at 4:41 PM
Edited May 3, 2013 at 4:49 PM
@syed263, XrmSvcToolkitTest.aspx contains some code snippets that you can use as reference, you don't necessarily need to upload the file. It's not a required file to run the toolkit, it basically contains all the unit tests that I wrote for the toolkit to cover some special scenarios such as Money field that you had trouble with.

You can open the file in any text editor, such as Notepad++, or Visual Studio.