locked
How to Stop Form from Auto-Populating a Field RRS feed

  • Question

  • I have a custom entity, related to the Account Entity (N:1 Relationship). The entity also includes a lookup field that is related to the Account Entity. When I open the form to create a new record the lookup field is auto-populated with the name of the Account in which I am creating the new record.

    Let me explain. I created a new entity to track additional information for each account. The information can change at any time which is the reason I am using a separate entity to track. That way a new record can be created each time the information changes and we have a history of the records. The new entity tracks the accounts' Rep and Rep Company.

    When I create a new rep record for ABC company the field for Rep Company is automatically populated with ABC Company. I am sure it has something to do with the way the field is setup on the form, but I have tried different settings and still get the same result.

    In the Properties for the field the "Related Records Filtering" is not activated. In the Additional Properties I have checked "Display Search Box in lookup dialog" and have a default view set to "Active Rep Companies". View Selector is "Show All Views".

    I do not have any code running on this form, can anyone tell me how to stop this field from auto-populating?

    Thanks in advance for any help.

    Thursday, March 27, 2014 12:04 PM

Answers

  • Hi Grlynn,

    That's the default behaviour. If you want the field to be blank, just wire up a JavaScript code on Page Load to blank out that lookup field.

    Xrm.Page.getAttribute(<lookup_Attribute>).setValue(null);
    


    Admin QuikView Solution for CRM 2013

    Thursday, March 27, 2014 12:42 PM

All replies

  • AFAIK that is a Standard CRM behavior.

    You can always create a plugin that changes the field value on Create.

    Thursday, March 27, 2014 12:34 PM
  • Hi Grlynn,

    That's the default behaviour. If you want the field to be blank, just wire up a JavaScript code on Page Load to blank out that lookup field.

    Xrm.Page.getAttribute(<lookup_Attribute>).setValue(null);
    


    Admin QuikView Solution for CRM 2013

    Thursday, March 27, 2014 12:42 PM
  • You might also add a check to only run the code Dynamotion suggested when the record is first being created.

    function Form_OnLoad() {
        if (Xrm.Page.ui.getFormType() === 1) {
            Xrm.Page.getAttribute( < lookup_Attribute > ).setValue(null);
        }
    }
    


    Jason Lattimer
    My Blog -  Follow me on Twitter -  LinkedIn

    Thursday, March 27, 2014 1:22 PM
    Moderator
  • Dynamotion,

    Thank you for the reply. I have not had any experience with writing JavaScript code for Dynamics.

    Can you tell me where I need to create the code or can you suggest some good references?

    Grylynn

    Thursday, March 27, 2014 1:26 PM
  • Dynamotion,

    Thank you for the reply. I have not had any experience with writing JavaScript code for Dynamics.

    Can you tell me where I need to create the code or can you suggest some good references?

    Grylynn

    To add javascript code you can follow this tutorial:

    http://happycrm.blogspot.com/2010/11/ms-crm-2011-my-first-experience-adding.html

    However I will first check if the field mapping for that field can be deleted, here some screenshot to check the mapping:

    http://stackoverflow.com/a/17315459/2191473


    My blog: www.crmanswers.net - Rockstar 365 Profile

    Thursday, March 27, 2014 1:56 PM
  • Thank you, I will go through the tutorials.

    Grlynn

    Thursday, March 27, 2014 2:07 PM
  • Thank you for the suggestion, yes I would only want the fields cleared if it is a new record.

    Grylynn

    Thursday, March 27, 2014 2:21 PM
  • I created the code and added it to the form. I also created an Event Handler for the Form_OnLoad function. When I open a new form nothing happens. I do not get any errors, but the fields are still populated. ( Saved and Published.)

    Here is the code I am using:

    function Form_OnLoad() {
        if (Xrm.Page.ui.getFormType() === 1) {
            Xrm.Page.getAttribute( "new_RepComp" ).setValue(null);
        }
    }

    I am not sure how to troubleshoot since there are no errors. Any suggestions?

    Grlynn

    Thursday, March 27, 2014 5:43 PM
  • Hi,

    If condition should have only == not === signs. please try to change it and also remove the space, field name to small case letter ("new_repcomp").



    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

    Thursday, March 27, 2014 5:51 PM
  • Thanks Vikram,

    I changed the code to:

    function Form_OnLoad() {
        if (Xrm.Page.ui.getFormType() == 1) {
            Xrm.Page.getAttribute("new_repcomp").setValue(null);
        }
    }

    Still get the same results with no errors.

    Thanks Grylnn

    Thursday, March 27, 2014 5:58 PM
  • Hi Grylnn,

    Make sure you wire up the method with the Form On Load from customizations and Publish it. If you have done that, try refreshing your browser cache, maybe close and reopen your browser.


    Admin QuikView Solution for CRM 2013

    Thursday, March 27, 2014 6:01 PM
  • I am sorry, I don't know what you mean by "wire up the method with the Form On Load from customizations". Can you explain please?

    Thanks Grlynn

    Thursday, March 27, 2014 6:37 PM
  • Hi Grylnn,

    In your form customization, have you added the .js file in Form Library and then added the Event Handler, as shown in the image below. Also make sure you Save and Publish once done.


    Admin QuikView Solution for CRM 2013

    Thursday, March 27, 2014 6:47 PM
  • Yes, I did that originally. Also just closed browser and reopened, but there is no change.

    I can try deleting the field mappings as Guido Preite suggested. (I really wanted to get the code to work though since it was my first attempt.) Does anyone know of any repercussions for deleting the mappings?

    Thanks.

    Grlynn

    Thursday, March 27, 2014 6:57 PM
  • Hi Grlynn,

    You shouldn't have problems removing the mappings. If it can be removed, that's the best possible solution and wouldn't cause any problem in the future.

    But if the mapping approach doesn't work, you can try debugging your script and check what is wrong.


    Admin QuikView Solution for CRM 2013

    Thursday, March 27, 2014 7:07 PM
  • No luck, I am unable to delete the Field Mappings. The error is: Could not delete Field Map. One or more of the field maps could not be deleted because they are being used by the Microsoft Dynamics CRM Platform.

    Thanks everyone for trying.

    Grlynn


    P.S. The only way I know how to debug is to open in IE. There were no errors.
    • Edited by Grlynn Thursday, March 27, 2014 7:52 PM Added P.S.
    Thursday, March 27, 2014 7:42 PM
  • Hi,

    I can see you are doing your best to run your first sample, so let's try to match steps.

    1. Open your solution, Navigate to Settings->Customizations->Customize the System)
    2. Navigate to your entity to make sure you are using correct field names (Components->Entities->YourEntityName->Fields), make sure you are using field Name, not schema name.
    3. Navigate to Web Resources (Solution->Components->Web Resources).
    4. Create new Web Resource, provide details and select Script(Jscript) under type dropdown.
    5. Click on Text Editor and paste your funciton, Save and Close and publish your webresource.
    6. Open your entity form, Navigate to (Components->Entities->YourEntityName->Forms->Double click on entity form to open it)
    7. Click on Form Properties from ribbon bar, it will open form properties window.
    8. Click on Add under Manage your libraries, select your webresource and click on Add.
    9. Click on Add under Manage functions (make sure Control->Form, Event->Onload is selected in respective dropdown).
    10.Select your webresource name from Library dropdown.
    11.Paste your function name (make sure to just past function name without (), for example just Form_OnLoad) and click Ok.
    12. Click ok to close form properties windows.
    13. Click on Save and then click on Publish.

    Now try to open your entity records and see if it's setting it null or not.


    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.

    Friday, March 28, 2014 12:20 AM
    Moderator
  • I finally got the code to work. Thanks to everyone that contributed.

    Not sure what I was doing wrong, but this morning with it worked just fine. I wasn't sure which reply to Mark as answer, as everyone helped. In the end I marked the first answer from Dynamotion. If there is a certain protocol I should use when marking as answer, please let me know.

    Grlynn

    Friday, March 28, 2014 12:12 PM