web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Setting a minimum quantity for an opportunity/quote/order product

(0) ShareShare
ReportReport
Posted on by

We have one item that we sell that has a minimum quantity of 5, what is the easiest (or the least painful) way in CRM to enforce that when creating a quote/order/opportunity? If it requires javascript an example would be helpful, since I don't write code.

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Royal King Profile Picture
    27,686 on at
    RE: Setting a minimum quantity for an opportunity/quote/order product

    Easiest solution to enforce this is by creating real time workflow and checking the product and quantity . If product matches and quantity is less than 5 stop the workflow with cancelled status and in the properties you can set the error message to show to the user.

    Below post provides detailed information on how to create real time workflow to achive this

    community.dynamics.com/.../using-real-time-workflows-to-show-error-messages.aspx

  • Aileen Gusni Profile Picture
    44,524 on at
    RE: Setting a minimum quantity for an opportunity/quote/order product

    DhPub,

    Yes using javascript, for example:

    function ValidateQuantity() {

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

       if(inputtedQuantity < 5)

       {

            alert("The Minimum Quantity to be purchased is 5");

       }

    }

    Registerd it on the onChangeEvent for field: Quantity in the Product Lines...

    Unfortunately you cannot use Business Rule because this form is not a refreshed UI Form..

    But if you need another criteria, such as the specific product then you need to write it before the above code to check what product.

    Or you can use Real Time workflow validation (but triggered only after you save), register it on the each Entity, Opportunity/Quote/Order Product.

    Or you can

    You want to limit like Like maybe paper, you only sell minimum 1 rim (500 sheets) or like Doughnut you only sell in 6 (1/2 dozen), if it is possible you create a Unit Group with base unit (the lowest level is 6), so you create at least 2 Units, 1 Piece and 5 Pieces, then if the user choose the Unit 1 Piece then you show prompt validation.

    Hope this helps.

    Thank you.

  • Community Member Profile Picture
    on at
    RE: Setting a minimum quantity for an opportunity/quote/order product

    Yeah, I tried the 1st suggestion and when using the new order form with the inline product section you can't add the product, it comes up with an  "ISV code aborted the operation". If I switch the view to the old information form then it works because you can add the quantity before the record is saved, but I don't want to use the old form.

    How do I implement that javascript for a particular item? I don't want to set that limit for all products.

  • Suggested answer
    Mahadeo Matre Profile Picture
    17,021 on at
    RE: Setting a minimum quantity for an opportunity/quote/order product

    You can do this by adding Javascript code, onLoad and OnSave of Quote.

    I am using CRMFetch toolkit in this example.. you can download it from 

    http://crmtoolkit.codeplex.com

    in Form library add cmrFetchkit.js

    and in Quote.js file add following code.

    function CheckPrductQuantity(productName) {    
        var fetchXml = ['<fetch distinct="false" mapping="logical" output-format="xml-platform" version="1.0">',
                          '<entity name="quotedetail">',
                            '<attribute name="productid"/>',
                            '<attribute name="productdescription"/>',
                            '<attribute name="priceperunit"/>',
                            '<attribute name="quantity"/>',
                            '<attribute name="extendedamount"/>',
                            '<attribute name="quotedetailid"/>',
                            '<order descending="false" attribute="productid"/>',
                            '<link-entity name="quote" alias="ab" to="quoteid" from="quoteid">',
                              '<filter type="and">',
                                '<condition attribute="quoteid" value="'+ Xrm.Page.data.entity.getId() +'" uitype="quote"  operator="eq"/>',
                              '</filter>',
                            '</link-entity>',
                          '</entity>',
                        '</fetch>'].join('');
    
        CrmFetchKit.FetchAll(fetchXml).then(function (quoteProducts) {
            for (var index in quoteProducts) {
                var quoteProd = quoteProducts[index];
                var quantity = quoteProd.attributes.quantity.value;
                var product = quoteProd.attributes.productid.name;
                if (productName == product) {
                    if (quantity < 5) {
                        Xrm.Page.ui.setFormNotification("Quantity should be greater than 5", "ERROR", "productQuantityError");
                    }
                    else {
                        Xrm.Page.ui.clearFormNotification("productQuantityError");
                    }
                }
            }
        }, onFetchError);
    }
    function onFetchError(xhr, status, errorThrown) {
        var errormsg = $(xhr.responseXML).find('Message').text();
        alert('CrmFetchKit-Error occured: ' + errormsg);
    }


    Call function on load and onSave of Quote.. 

    If quantity is less than 5, then message will be shown on quote form. 

    Hope this will help to solve your issue. 

    Thanks, 

  • Aileen Gusni Profile Picture
    44,524 on at
    RE: Setting a minimum quantity for an opportunity/quote/order product

    DhPub,

    You can use odata query to get the Product.

    missdynamicscrm.blogspot.com/.../tips-and-trick-odata-crm-2011-2013.html

    Btw what is your rule, you need setting in the Master? Minimum Quantity or hard code to 5?

    Thank you.

  • Community Member Profile Picture
    on at
    RE: Setting a minimum quantity for an opportunity/quote/order product

    I must be missing a piece. When I add everything above (copy/paste the code, then add the product as the parameter) I get an error 'CheckProductQuantity' is undefined

  • Community Member Profile Picture
    on at
    RE: Setting a minimum quantity for an opportunity/quote/order product

    Ignore this one,  still having the issue I stated above about 'CheckProductQuantity' being undefined

  • Mahadeo Matre Profile Picture
    17,021 on at
    RE: Setting a minimum quantity for an opportunity/quote/order product

    have you published web resources and form?

  • Community Member Profile Picture
    on at
    RE: Setting a minimum quantity for an opportunity/quote/order product

    Ok, after some dumb spelling errors on my part. I get the following error (comes up in a windows behind the quote window, I don't see it until I close the quote window). One of those "CRM has encountered an error...."

    I copied and pasted the code you supplied exactly as you posted it. Was I supposed to make any changes?

    Microsoft Dynamics CRM Error Report Contents

    <CrmScriptErrorReport>

     <ReportVersion>1.0</ReportVersion>

     <ScriptErrorDetails>

      <Message>Unable to get property 'attributes' of undefined or null reference</Message>

      <Line>24</Line>

      <URL></URL>

      <PageURL>/_forms/read/page.aspx?etc=1084&pagemode=iframe&theme=Outlook15White</PageURL>

      <Function>anonymousr:Unabletogetproperty'attributes'ofundefinedornullreference</Function>

      <CallStack>

       <Function>anonymousr:Unabletogetproperty'attributes'ofundefinedornullreference</Function>

      </CallStack>

     </ScriptErrorDetails>

     <ClientInformation>

      <BrowserUserAgent>Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; WOW64; Trident/7.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E; InfoPath.3)</BrowserUserAgent>

      <BrowserLanguage>en-US</BrowserLanguage>

      <SystemLanguage>en-US</SystemLanguage>

      <UserLanguage>en-US</UserLanguage>

      <ScreenResolution>1920x1080</ScreenResolution>

      <ClientName>Outlook Laptop - Online</ClientName>

      <ClientTime>2015-02-02T14:14:16</ClientTime>

     </ClientInformation>

     <ServerInformation>

       <OrgLanguage>1033</OrgLanguage>

       <OrgCulture>1033</OrgCulture>

       <UserLanguage>1033</UserLanguage>

       <UserCulture>1033</UserCulture>

       <OrgID>{36306EC9-9232-48C1-AD1F-29EA1A997D3B}</OrgID>

       <UserID>{F4232855-A99D-E011-9C19-001E67026524}</UserID>

       <CRMVersion>6.1.1.132</CRMVersion>

     </ServerInformation>

    </CrmScriptErrorReport>

  • Verified answer
    Mahadeo Matre Profile Picture
    17,021 on at
    RE: Setting a minimum quantity for an opportunity/quote/order product

    try adding Jquery1.10.2 or latest jquery library on your form.

    You can get Jquery library from http://jquery.com/download/

    Or.. 

    I uploaded my code and CRM managed solution to 

    https://onedrive.live.com/?cid=313F10AE62A84B48&id=313F10AE62A84B48%21119

    Solution Name : QuoteProduct_1_0_0_0_managed.zip

    Hope this will solve your all error.. 

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…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
HR-09070029-0 Profile Picture

HR-09070029-0 2

#1
UllrSki Profile Picture

UllrSki 2

#3
ED-30091530-0 Profile Picture

ED-30091530-0 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans