locked
Call a custom javascript function on click of OOB ribbon button on Quote entity - URGENT RRS feed

  • Question

  • Hello All,

    I am trying to implement a validation on click of "Activate Quot" button on Quote entity.

    I have to capture today's date on click of this button and set it to a custom date field on the form.

    I found lot of example of custom ribbon button, but could not find for OOB buttons.

    Can anyone help if it is possible to implement with the step by step process?

    Any step by step link for the blogs, would be awesome.

    It would be a great help.

    Thanks for looking.


    Puneet Joshi - Dynamics CRM Developer

    Monday, November 25, 2013 6:54 AM

Answers

  • Hi,

    Can you refer this link:

    Override OOB button

    The function to be called for your activate Quote is "activateQuote".

    In case you need any help, let me know. I hope overriding the OOB button should not be a problem for you.

    Moreover to implement the custom logic is to first identify the actual function which is being called from the OOB button which in your case is "activateQuote". This you can find from the SDK "CRMSDK\samplecode\cs\client\ribbon\exportribbonxml\bin\Debug\ExportedRibbonXml\quoteRibbon.xml" file.

                      <Button Id="Mscrm.Form.quote.ActivateQuote" Command="Mscrm.Form.quote.ActivateQuote" Sequence="6" Alt="$Resources:Ribbon.Form.quote.MainTab.Actions.ActivateQuote" LabelText="$Resources:Ribbon.Form.quote.MainTab.Actions.ActivateQuote" Image16by16="/_imgs/SFA/ActivateQuote_16.png" Image32by32="/_imgs/SFA/ActivateQuote_32.png" TemplateAlias="o1" ToolTipTitle="$Resources:Mscrm_Form_quote_MainTab_Actions_ActivateQuote_ToolTipTitle" ToolTipDescription="$Resources:Mscrm_Form_quote_MainTab_Actions_ActivateQuote_ToolTipDescription" />
    
    <CommandDefinition Id="Mscrm.Form.quote.ActivateQuote">
            <EnableRules>
              <EnableRule Id="Mscrm.QuoteIsInDraftState" />
            </EnableRules>
            <DisplayRules />
            <Actions>
              <JavaScriptFunction FunctionName="activateQuote" Library="/_static/SFA/quotes/quote.js" />
            </Actions>
    </CommandDefinition>

    Once you have identified the function being called then you can implement your javascript function and perform the validation and then call the actual function which was being called by default or viceversa (call default function and then perform your validation. This in your case should not be there as once the Quote is activated you will not be able to change to it.)

    I hope this resolves your issue.

    Thanks & Regards,


    Anubhav Bajpai

    • Marked as answer by Puneet Joshi Monday, November 25, 2013 1:37 PM
    Monday, November 25, 2013 9:49 AM

All replies

  • Hi Puneet,

        As the OOTB button defines it's own functionality you cannot insert javascript there. But what you are trying to achieve, you should be able to do using CRM workflow. You can create a workflow which will be fired on change of the status change and in the workflow check if the status is what you desire, update the date. Here is some article which could help.

    http://stackoverflow.com/questions/6151949/dynamics-crm-current-date-placeholder-in-workflows

    http://mscrmandsqlserver.wordpress.com/2011/11/26/how-to-use-current-datetime-in-crm-workflow/


    Hope this helps.
     
    -----------------------------------------------------------------------
     Minal Dahiya
    blog : http://minaldahiya.blogspot.com.au/

     
    If this post answers your question, please click "Mark As Answer" on the post and "Vote as Helpful"

    • Proposed as answer by Minal Dahiya Monday, November 25, 2013 7:20 AM
    Monday, November 25, 2013 7:20 AM
  • Workflow may not be possible on every OOB button as it is not changing state. I need to insert my cutom script also with OOB ribbon click functionality.

    Any other suggestions. I already tried your suggestion but not successful on every OOB button.


    Puneet Joshi - Dynamics CRM Developer

    Monday, November 25, 2013 7:28 AM
  • Could you please explain more about your requirement what you want to achieve ?

    Hope this helps. If you get answer of your question, please mark the response as an answer and vote as helpful !!!
    Vikram Singh. !!!  My Blog

    Monday, November 25, 2013 7:39 AM
  • Other workaround could be to hide OOB button and create custom button with your specific requirement + oob functionality.


    Our Website | Our Blog | Follow US | My Facebook Page | Microsoft Dynamics CRM 2011 Application Design
    Make sure to "Vote as Helpful" and "Mark As Answer",if you get answer of your question.

    Monday, November 25, 2013 8:38 AM
    Moderator
  • Hi,

    Can you refer this link:

    Override OOB button

    The function to be called for your activate Quote is "activateQuote".

    In case you need any help, let me know. I hope overriding the OOB button should not be a problem for you.

    Moreover to implement the custom logic is to first identify the actual function which is being called from the OOB button which in your case is "activateQuote". This you can find from the SDK "CRMSDK\samplecode\cs\client\ribbon\exportribbonxml\bin\Debug\ExportedRibbonXml\quoteRibbon.xml" file.

                      <Button Id="Mscrm.Form.quote.ActivateQuote" Command="Mscrm.Form.quote.ActivateQuote" Sequence="6" Alt="$Resources:Ribbon.Form.quote.MainTab.Actions.ActivateQuote" LabelText="$Resources:Ribbon.Form.quote.MainTab.Actions.ActivateQuote" Image16by16="/_imgs/SFA/ActivateQuote_16.png" Image32by32="/_imgs/SFA/ActivateQuote_32.png" TemplateAlias="o1" ToolTipTitle="$Resources:Mscrm_Form_quote_MainTab_Actions_ActivateQuote_ToolTipTitle" ToolTipDescription="$Resources:Mscrm_Form_quote_MainTab_Actions_ActivateQuote_ToolTipDescription" />
    
    <CommandDefinition Id="Mscrm.Form.quote.ActivateQuote">
            <EnableRules>
              <EnableRule Id="Mscrm.QuoteIsInDraftState" />
            </EnableRules>
            <DisplayRules />
            <Actions>
              <JavaScriptFunction FunctionName="activateQuote" Library="/_static/SFA/quotes/quote.js" />
            </Actions>
    </CommandDefinition>

    Once you have identified the function being called then you can implement your javascript function and perform the validation and then call the actual function which was being called by default or viceversa (call default function and then perform your validation. This in your case should not be there as once the Quote is activated you will not be able to change to it.)

    I hope this resolves your issue.

    Thanks & Regards,


    Anubhav Bajpai

    • Marked as answer by Puneet Joshi Monday, November 25, 2013 1:37 PM
    Monday, November 25, 2013 9:49 AM
  • Anubhav,

    I will try this approach. Can i PM you if i get stuck?

    Your ID pls.

    Let me know.


    Puneet Joshi - Dynamics CRM Developer

    Monday, November 25, 2013 1:38 PM
  • Hi,

    You may update this post itself so that any help points which may come up might prove to be helpful to the community.

    Thanks & Regards,

    Anubhav


    Anubhav Bajpai

    Monday, November 25, 2013 1:48 PM
  • Hello Minal,

    I was evaluating the approaches, as per your suggestion I wrote one OOB Workflow, once the Quote Status Changes from Draft to Active as a condition then set custom date filed to current date (Plugin Execution date) and also set a custom status picklist to some value.

    But the Workflow fails and reason is because Fields are Read Only .. I think the Quote is Activated, by design it doesnot allow any modification done on Activated Quote Record. Now Custom JScript on OOB ribbon only looks one possible way. I wrote plugin also if status updates to Active and it gives the same error that fields are Read Only.

    What is your take on this. Let me know.


    Puneet Joshi - Dynamics CRM Developer

    Tuesday, December 3, 2013 3:00 AM
  • Vikram,

    What is not clear to you, please let me know.

    I have to capture the date when the Quote gets Activated and show on form, also a custom picklist called status to some value. To do so workflow and plugin both failing stating reason "Fields are read only".

    Let me know if you need any other info.

    Thanks.


    Puneet Joshi - Dynamics CRM Developer

    Tuesday, December 3, 2013 3:02 AM
  • Hi Puneet,

    It can be done using plugin. As you said you have written a plugin but giving "Fields are read only" error.

    Try to register your plugin on Pre-Validation or Pre-Operation stage and don't try to update quote record just pass the attribute values on the entity object.

    like :

    entity.Attributes["new_datefield"] = new DateTime(DateTime.Now);


    Hope this helps. If you get answer of your question, please mark the response as an answer and vote as helpful !!!
    Vikram Singh. !!!  My Blog

    Tuesday, December 3, 2013 3:14 AM