Set up subgrid when creating a record RRS feed

  • Question

  • Hello!

    I've added a sub grid in the Incident form, it shows the KB Articles that have the same Classification of the Incident.

    This is working well when I open an existing Incident, however it doesn't work when creating a new Incident.

    In the sub grid is "to enable this content, save the record"

    I expect this behavior when the records are related, however I'm doing a query and setting up the sub grid.

    Any one could help me with this?

    Wednesday, January 22, 2014 12:39 PM

All replies

  • Sub grid is a relationship between entity A and entity B. When you are creating the record, for sure the sub grid will show that message because the record for entity A still not exist. So, you cannot set the relationship. Simple idea for this, engine is entity A, car is entity A. The engine is still not exist, so the car will not moving at all =)
    • Proposed as answer by mr_nougat Thursday, January 23, 2014 4:47 AM
    Thursday, January 23, 2014 4:47 AM
  • I think your problem is that the field you are using for your query "Classification" has not been committed to the database yet because you have not saved your record. I don't know that you are going to be able to achieve this using out of the box sub grids for this very reason. You may have to look at implementing something using form script and/or a custom web resource.

    Thursday, January 23, 2014 6:45 AM
  • Yes, I understand that it shouldn't show the default grid for the relationship Incident-KbArticle, but I'm setting up the FetchXml for the grid, and here there is not relationship, just a query.
    Thursday, January 23, 2014 9:19 AM
  • Yes, Classification has value. I'm checking now with an alert.

    I call this method in the On_Load method and when Classification changes.

    function Form_OnLoad() { ... if (formType == "1") { ...} else { //Check if there is/are article(s) with the same subject of the case check_articles(); } function check_articles() { var KBArtGrid = document.getElementById('grid_kb_articles'); if (KBArtGrid == null) { //make sure the grid has loaded setTimeout(function () { check_articles(); }, 500); //if the grid hasn’t loaded run this again when it has return; } var classificationValue = new Array(); classificationValue = Xrm.Page.getAttribute("subjectid").getValue(); if(classificationValue != null && classificationValue[0] != null) {

    alert(classificationValue[0].name); var fetchXml = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>" + " <entity name='kbarticle'>" + " <attribute name='number' />" + " <attribute name='title' />" + " <attribute name='statecode' />" + " <attribute name='kbarticletemplateid' />" + " <order attribute='number' descending='false' />" + " <filter type='and'>" + " <condition attribute='subjectidname' operator='like' value='" + '%' +classificationValue[0].name +'%'+ "' />" + " </filter>" + " </entity>" + " </fetch>"; KBArtGrid.control.SetParameter("fetchXml", fetchXml); KBArtGrid.control.Refresh();

    So, when I try to create a new Incident, it is doing the same process as when I open an existing record.

    Thursday, January 23, 2014 9:22 AM
  • I dont think u can do that. Because there are some CRM internal function that will detect the form type. But to solve this, maybe you can use Silverlight or html web resource to show the grid.
    Thursday, January 23, 2014 9:51 AM