locked
set default product quantity RRS feed

  • Question

  • Hi all

    On the Quote Product entity, I want to set the default value for quantity as 1 when a new Quote Product is added.  It works, but I get an error.  See image and code

    function DefaultQuantity() {
        if (Xrm.Page.data.entity.attributes.get("quantity").getValue() == null) {
               Xrm.Page.data.entity.attributes.get("quantity").setValue(parseFloat(1));
        }
    }

    thanx


    Please vote if you find my post useful. Add me on Skype @ christo.skype1

    Thursday, April 26, 2012 8:23 AM

All replies

  • You Can Try this code:

    Just change the field to text field or Whole number.

    function DefaultQuantity() {

    var quantity = Xrm.Page.getAttribute("quantity");

    if(quantity.getValue() == null) {

    quantity.setValue("1");

    }

    }


    Naren


    • Edited by Naren MN Wednesday, May 16, 2012 5:32 AM
    Wednesday, May 16, 2012 5:30 AM
  • I remember this happening to me when attempting to set the Quantity on Form Load.  I had several attempts at coding around it, until giving up after debugging the CRM Javascript that generates the error.

    My final solution (can't remember for which client I encountered the issue so the following is pseudo-code from memory) was something like:

    function DefaultQuantity() {
    	window.setTimeout(function () {
    		if (Xrm.Page.data.entity.attributes.get("quantity").getValue() == null) {
    			Xrm.Page.data.entity.attributes.get("quantity").setValue(parseFloat(1));
    		}
    	}, 500);
    }
    Basically; "something" in the form wasn't ready for me to set the Quantity attribute and either the delay or merely spawning the function gave it the opportunity to correct itself.


    --pogo (pat) @ pogo69.wordpress.com

    Wednesday, May 16, 2012 5:44 AM