locked
HTML Web Resource with java script. how to save data into entity RRS feed

  • Question

  • I am new to CRM. I am using dynamic CRM 365 recent version in which i want to add HTML web resource. i.e. HTML page into my Entity.

    There are two input fields on page along with 1 save button. I want to save field data into my entity on click of Save button. Please help me how to write Javascript code to implement the same.

    

    • Edited by MS_User_007 Thursday, October 26, 2017 1:29 PM Changed Screenshot
    Thursday, October 26, 2017 1:16 PM

Answers

  • In this case you can use something like following function for onclick of your button - put fields you want to save to on form of your record:

    function saveShanges(){
    var Xrm = parent.Xrm;
    
    Xrm.Page.getAttribute("firstfield").setValue(document.getElementById("yourhtmlelementid").value);
    Xrm.Page.getAttribute("secondfield").setValue(document.getElementById("yourotherhtmlelementid").value);
    }

    Good luck.


    Dynamics CRM/Business Solutions MVP
    Read My blog

    Tuesday, October 31, 2017 12:58 PM
    Moderator
  • If it gives that error I can assume that fields company name and mobile are not on the form. Put it there.

    I can't give you urls because I don't know such article except mine - https://butenko.pro/2015/03/01/howto-htmljs-webresources/

    Also I believe you have the same search engines available (like Bing or Google) so you can easily check it for articles available online.


    Dynamics CRM/Business Solutions MVP
    Read My blog

    Wednesday, November 1, 2017 10:39 AM
    Moderator

All replies

  • Hello,

    You can CrmRestBuilder to build code that you need and use it in onclick handler of your Save Button.


    Dynamics CRM/Business Solutions MVP
    Read My blog

    Thursday, October 26, 2017 1:46 PM
    Moderator
  • Thanks...!!! How this would work in my case? I just want to save values of 2 custom fields which are created using Web resource to be saved in entity using custom save button. i.e. using onclick event. how to implement this?
    Monday, October 30, 2017 8:01 AM
  • Ok. Where do you want to save those values?

    Dynamics CRM/Business Solutions MVP
    Read My blog

    Monday, October 30, 2017 1:36 PM
    Moderator
  • I want to save those values in my entity. entity name is MyEntity and on Main form of that entity i have added those field and custom button using html web resource.

    Now i want some custom logic like by clicking on custom "Save" button these custom fields values get saved into Entity just like other fields value.

    Tuesday, October 31, 2017 11:02 AM
  • In this case you can use something like following function for onclick of your button - put fields you want to save to on form of your record:

    function saveShanges(){
    var Xrm = parent.Xrm;
    
    Xrm.Page.getAttribute("firstfield").setValue(document.getElementById("yourhtmlelementid").value);
    Xrm.Page.getAttribute("secondfield").setValue(document.getElementById("yourotherhtmlelementid").value);
    }

    Good luck.


    Dynamics CRM/Business Solutions MVP
    Read My blog

    Tuesday, October 31, 2017 12:58 PM
    Moderator
  • Hi,

    You can go through below link..

    https://community.dynamics.com/crm/f/117/t/221405

    Hope this help.

    Thanks

    Tuesday, October 31, 2017 1:56 PM
  • hello Andrew,

    I have tried your code but it is giving me below error and not saving data into my entity. I am calling this function on click of my custom button.

    Code***************************

    function saveShanges(){
    var Xrm = parent.Xrm;

    Xrm.Page.getAttribute("new_companyname").setValue(document.getElementById("Cname").value);
    Xrm.Page.getAttribute("new_mobile").setValue(document.getElementById("Cmob").value);
    }

    ******************************************

    Error :

    Cannot read property 'setValue' of null

    It would be very helpful for me if you provide links to implement such example.(HTML web resource with custom fields and custom save functionality)

    Wednesday, November 1, 2017 7:26 AM
  • If it gives that error I can assume that fields company name and mobile are not on the form. Put it there.

    I can't give you urls because I don't know such article except mine - https://butenko.pro/2015/03/01/howto-htmljs-webresources/

    Also I believe you have the same search engines available (like Bing or Google) so you can easily check it for articles available online.


    Dynamics CRM/Business Solutions MVP
    Read My blog

    Wednesday, November 1, 2017 10:39 AM
    Moderator
  • Thanks Andrew..!!! there is no problem in code, it is working fine. I have not put fields on form due to which it was giving me an error. I thought it will save my data into fields without adding that fields on create form, and I can see those fields data in view.
    • Edited by MS_User_007 Friday, November 3, 2017 10:56 AM spelling mistakes corrected
    Thursday, November 2, 2017 10:43 AM