简体   繁体   中英

Updating field in CRM 2011 through javascript from ribbon button on homegrid view

I am trying to create a button on the initial list or homegrid view of leads that will set the value of a specific field to the same value every time for the lead that is selected. Anyone know how i can do this through javascript?

Thanks!

To build on James's answer, you can use the CrmParameter SelectedControlSelectedItemIds to get a list of all the leads selected in a homepage grid. There is an answer on the MSDN forums that explains how to do this, copied below. You can do this in the Xml source or in the two CRM ribbon editors I know of.

After that, you would then need to use the Update method of one of the CRM webservices to loop through the Guid array and update each entity/database row accordingly. I've mentioned Avanade's excellent web resource before, and MSDN has some additional documention on this as well.

<CommandDefinition Id="Account.Form.CustomGroup.Button.A.Command">
  <Actions>
    <JavaScriptFunction Library="$webresource:AccountFormLibrar"
                        FunctionName="CreateNewAccount">
      <CrmParameter Value="SelectedControlSelectedItemIds"/>
    </JavaScriptFunction>
  </Actions>
</CommandDefinition>
function CreateNewAccount (prmRecordGUID) {
    //prmRecordGUID will recieve all GUIDS in comma seperated i.e. GUID1,GUID2,GUID3
}

Yeah this should be pretty straightforward - I dont think what you have said in your comment will work - that function you are trying to use only works if the form of the record is open, eg it wont work from a grid view.

You will have to use a webservice call as described in the MSDN here: http://msdn.microsoft.com/en-us/library/hh771584#BKMK_DataAccessUsingJavaScript

Also if you are customising the ribbon (adding buttons) you would find it a lot easier with this tool: http://www.develop1.net/public/page/Ribbon-Workbench-for-Dynamics-CRM-2011.aspx

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM