locked
CRM 2015 add button on form RRS feed

  • Question

  • Hii,

    I need a help to add button on form, I have tried by using the following like but i am unable to do that successfully.

    https://social.microsoft.com/Forums/en-US/75758803-521f-4730-ab74-cd02cbb56842/add-a-button-to-crm-2011-form?forum=crmdevelopment

    I have created web resource, one field by the name 'buttonfield' and added following code

    function onLoad() { ConvertToButton('new_buttonfield', 'ButtonText','100px',FunctionName,'Button Label'); } function ConvertToButton(fieldname, buttontext, buttonwidth,clickevent, title) { //check if object exists; else return if (document.getElementById(fieldname) == null) { return; } functiontocall=clickevent; crmForm.all[fieldname].DataValue = buttontext; crmForm.all[fieldname].readOnly = true; crmForm.all[fieldname].style.borderRight="#3366cc 1px solid"; crmForm.all[fieldname].style.paddingRight="5px"; crmForm.all[fieldname].style.borderTop="#3366cc 1px solid"; crmForm.all[fieldname].style.paddingLeft="5px"; crmForm.all[fieldname].style.fontSize="11px"; crmForm.all[fieldname].style.backgroundImage="url(/_imgs/btn_rest.gif)"; crmForm.all[fieldname].style.borderLeft="#3366cc 1px solid"; crmForm.all[fieldname].style.width=buttonwidth; crmForm.all[fieldname].style.cursor="hand"; crmForm.all[fieldname].style.lineHeight="18px"; crmForm.all[fieldname].style.borderBottom="#3366cc 1px solid"; crmForm.all[fieldname].style.backgroundRepeat="repeat-x"; crmForm.all[fieldname].style.fontFamily="Tahoma"; crmForm.all[fieldname].style.height="20px"; crmForm.all[fieldname].style.backgroundColor="#cee7ff"; crmForm.all[fieldname].style.textAlign="center"; crmForm.all[fieldname].style.overflow="hidden"; crmForm.all[fieldname].attachEvent("onmousedown",push_button); crmForm.all[fieldname].attachEvent("onmouseup",release_button); crmForm.all[fieldname].attachEvent("onclick",functiontocall); crmForm.all[fieldname].style.lineHeight="14px"; crmForm.all[fieldname+'_c'].style.visibility = 'hidden'; crmForm.all[fieldname].title=title; window.focus(); function push_button(){ window.event.srcElement.style.borderWidth="2px"; window.event.srcElement.style.borderStyle="groove ridge ridge groove"; window.event.srcElement.style.borderColor="#3366cc #4080f0 #4080f0 #3366cc"; } function release_button(){ window.event.srcElement.style.border="1px solid #3366cc"; } } // now the definition of the function to call on button click function FunctionName() { // do something }

    AND onLoad call on form load event

    please let me know where i get missed.....

    Thanks

    Thursday, November 5, 2015 2:13 PM

All replies

  • Thursday, November 5, 2015 2:58 PM
  • document.getElementById(fieldname) is not supported. Which version of CRM are you working on? Can you take the webresources route to add the button in a HTML page?
    Thursday, November 5, 2015 9:42 PM
  • Thanks,

    I have done this.....but i have other issue while import translation ....

    I am using CRM 2015 and doing costume entity and export it, that costume entity needs to import in new fresh environment on CRM 2015 or i have delete it after export entity...but i hv got the SQL error on same screen here is the stack trace from event viewer 

    The Web Service plug-in failed in OrganizationId: 8215693e-09a8-419a-8f01-64a694b3e0bc; SdkMessageProcessingStepId: a7da5338-643a-4300-9822-54bb7cf522fc; EntityName: none; Stage: 30; MessageName: ImportTranslation; AssemblyName: Microsoft.Crm.Extensibility.InternalOperationPlugin, Microsoft.Crm.ObjectModel, Version=7.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35; ClassName: Microsoft.Crm.Extensibility.InternalOperationPlugin; Exception: Unhandled Exception: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
       at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
       at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
       at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
       at System.Web.Services.Protocols.LogicalMethodInfo.Invoke(Object target, Object[] values)
       at Microsoft.Crm.Extensibility.InternalOperationPlugin.Execute(IServiceProvider serviceProvider)
       at Microsoft.Crm.Extensibility.V5PluginProxyStep.ExecuteInternal(PipelineExecutionContext context)
       at Microsoft.Crm.Extensibility.VersionedPluginProxyStepBase.Execute(PipelineExecutionContext context)
    Inner Exception: System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary.
       at Microsoft.Crm.Tools.ImportExportPublish.TranslationImportHandlerBase.DoUpdate(Dictionary`2 cellToLanguageDictionary, Dictionary`2 locLabels, Int32 baseLanguageCode, ReadOnlyCollection`1 provisionedLanguages, XmlNode row, String key, Int32 rowCount, Guid objectId, String objectColumnName)
       at Microsoft.Crm.Tools.ImportExportPublish.RootTranslationImportHandler.ImportLocalizedLabelStringsIfRequired(XmlDocument importDocument, Dictionary`2 locLabels, Dictionary`2 cellToLanguageDictionary, Int32 baseLanguageCode, ReadOnlyCollection`1 provisionedLanguages)
       at Microsoft.Crm.Tools.ImportExportPublish.RootTranslationImportHandler.ImportLocalizedLabelStrings(XmlDocument importDocument, Int32 baseLanguageCode, ReadOnlyCollection`1 provisionedLanguages)
       at Microsoft.Crm.Tools.ImportExportPublish.TranslationImportHandlerBase.RunImportTranslations(Int32 baseLanguageCode, ReadOnlyCollection`1 provisionedLanguages)
       at Microsoft.Crm.Tools.ImportExportPublish.LanguageTranslations.ImportTranslationsWithProgress(String importXml, Guid jobId)
       at Microsoft.Crm.WebServices.TranslationImportExportService.ImportTranslationsInternal(String crmTranslationsXml, Guid& importJobId, ExecutionContext context)
       at Microsoft.Crm.WebServices.TranslationImportExportService.ImportTranslation(String translationXmlFileName, Byte[] translationFile, Guid& importJobId, ExecutionContext context)
       at Microsoft.Crm.WebServices.LangTranslationsService.ImportTranslation(Byte[] translationFile, Guid importJobId, ExecutionContext context)

    i have used http://www.microsoft.com/en-us/dynamics/crm-customer-center/import-translated-entity-and-field-text.aspx for import export....

    Please suggest me..

    Thanks,

    Ganesh

    Friday, November 6, 2015 5:06 PM