locked
How to add javascript with sub-grid inside the entity RRS feed

  • Question

  • Am Using 2 entities in this process (contact & external).

    Inside the contact entity( i displayed a Subgrid which showing  'external' entity records).

    If i changed a field in 'contact' entity, it would create a new record in 'external' entity. I done the script.

    Am trying to do in a reverse way, i.e., if someone create a new record using 'subgrid' then Add new record, the field should change back. If any idea/advise, please share

    Thanks

    Wednesday, July 17, 2013 2:01 PM

Answers

  • You need to put your script on Load of external.

    You will first check that the form type is 1 so that this event should run on create only like:-

    getFormType: function () { var FORM_TYPE_CREATE = 1; var FORM_TYPE_UPDATE = 2; var FORM_TYPE_READ_ONLY = 3; var FORM_TYPE_DISABLED = 4; var FORM_TYPE_QUICK_CREATE = 5; var FORM_TYPE_BULK_EDIT = 6; var formType = Xrm.Page.ui.getFormType(); if (formType == FORM_TYPE_CREATE) { //Put your code here } else { } }//Now you can any of two methods to update the parent record field.

    1.

    window.top.opener.parent.Xrm.Page.getAttribute("ATTRIBUTESCHEMANAME").setValue("Hello");

    2. You can use oData to update parent form

    http://www.toplinestrategies.com/dotneters/ms-crm/microsoft-crm-2011-update-odata-example/?lang=en


    Regards Faisal

    • Marked as answer by prakashmsdyn Wednesday, July 17, 2013 3:23 PM
    Wednesday, July 17, 2013 2:47 PM
  • Hi,

    I understand this: you want to change a field back on the contact, when a new record of external is created. Why you don't use a plugin instead of a JavaScript? A plugin for this purpose allows you more reliable and better way to do your requirement (as you could achieve this requirement through the JavaScript also, call a function on the save of the external and check the form type, if it is new, then you could send the update through a post http requrest. have a look at this link for an example). You could register a plugin to intercept the create message of the external entity, then, if it met certain conditions you could update the desired field on the contact. Have a look at this link if you are not familiar with CRM 2011 plugins.



    My Weblog | My Website

    Wednesday, July 17, 2013 2:47 PM
    Moderator

All replies

  • You need to put your script on Load of external.

    You will first check that the form type is 1 so that this event should run on create only like:-

    getFormType: function () { var FORM_TYPE_CREATE = 1; var FORM_TYPE_UPDATE = 2; var FORM_TYPE_READ_ONLY = 3; var FORM_TYPE_DISABLED = 4; var FORM_TYPE_QUICK_CREATE = 5; var FORM_TYPE_BULK_EDIT = 6; var formType = Xrm.Page.ui.getFormType(); if (formType == FORM_TYPE_CREATE) { //Put your code here } else { } }//Now you can any of two methods to update the parent record field.

    1.

    window.top.opener.parent.Xrm.Page.getAttribute("ATTRIBUTESCHEMANAME").setValue("Hello");

    2. You can use oData to update parent form

    http://www.toplinestrategies.com/dotneters/ms-crm/microsoft-crm-2011-update-odata-example/?lang=en


    Regards Faisal

    • Marked as answer by prakashmsdyn Wednesday, July 17, 2013 3:23 PM
    Wednesday, July 17, 2013 2:47 PM
  • Hi,

    I understand this: you want to change a field back on the contact, when a new record of external is created. Why you don't use a plugin instead of a JavaScript? A plugin for this purpose allows you more reliable and better way to do your requirement (as you could achieve this requirement through the JavaScript also, call a function on the save of the external and check the form type, if it is new, then you could send the update through a post http requrest. have a look at this link for an example). You could register a plugin to intercept the create message of the external entity, then, if it met certain conditions you could update the desired field on the contact. Have a look at this link if you are not familiar with CRM 2011 plugins.



    My Weblog | My Website

    Wednesday, July 17, 2013 2:47 PM
    Moderator