locked
Filtering not able to save RRS feed

  • Question

  • Hi,

    Am applying filters on the option-set to get the lookup field value. here is the code:

    function SetFilterLookup() {
    //debugger;
        if ((Xrm.Page.getAttribute("optionsetval").getSelectedOption() != null)&&(Xrm.Page.getAttribute("lookup1").getValue() != null)) {
            var _Text = Xrm.Page.getAttribute("optionsetval").getSelectedOption().text;
    if(_Text=='title')
    _Text='title_name';
          var _Value = Xrm.Page.getAttribute("optionsetval").getSelectedOption().value;
          var countyId= Xrm.Page.getAttribute("lookup1").getValue()[0].id;
     //alert(guid_lkp);
            var viewId = '{30A7616D-6A84-E211-0000-0000569C13E4}';
            var entityName = "contact";
            var viewDisplayName = "Active contacts for " + _Text;
            var fetchXml = "
    .....
    .......
    ....";

            //build grid layout
            var layoutXml = "....
    .....
    ..
    ";
            //add new view
    Xrm.Page.getControl("lookup2").addCustomView(viewId, entityName, viewDisplayName, fetchXml, layoutXml, true);   
        }
    }

    everything works fine until i save the form, the lookup2 which am setting to the form is going empty.  any help would greatly be appreciated

    Wednesday, August 7, 2013 8:09 PM

Answers

  • Hi,

    I fixed the problem. actually my fetchxml was missing one attribute that is in the layoutxml.

    Thanks for the inputs guys.

    Note- fetchxml attributes and layoutxml attributes need be same.  :)

    Thanks

    Gary

    • Marked as answer by gary_23 Thursday, August 8, 2013 2:51 PM
    Thursday, August 8, 2013 2:51 PM

All replies

  • Hi Gary,

    Can you update these lines as mentioned under:

    document.getElementById("lookup2").disableViewPicker = 0;

    Xrm.Page.getControl("lookup2").addCustomView(viewId, entityName, viewDisplayName, fetchXml, layoutXml, true); 

    document.getElementById("lookup2").disableViewPicker = 1;

    These properties are disabled by default, before setting them up, you need to enable them, then set them and again disable them.

    I hope this works for you.


    Anubhav Bajpai

    Thursday, August 8, 2013 2:35 AM
  • Hi Anubhav,

    I used the above code of disableviewpicker. still seems to be not saving, after debugging found that

    Xrm.Page.getControl("lookup2").addCustomView(viewId, entityName, viewDisplayName, fetchXml, layoutXml, true);

    This line shows undefined, is there anything wrong with this line.

    Thanks.

    Gary

    Thursday, August 8, 2013 3:01 AM
  • Can you check with the double quotes in case you copied the code.

    moreover verify the entityName as "Contact" instead of "contact".


    Anubhav Bajpai

    Thursday, August 8, 2013 4:00 AM
  • changing the Contact instead of contact is throwing an error. here is my ...

     var fetchXml = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='true'>"+
                       "<entity name='contact'>"+
                       "<attribute name='fullname'/>"+
                       "<attribute name='new_field1'/>"+
                       "<attribute name='new_field2'/>"+
                        "<filter type='and'>"+
                       "<condition attribute='new_field1' operator='eq' value='"+ _Text + "'/>"+
                       "<condition attribute='new_field2' operator='eq' value='"+ countyId+ "'/>"+
                      "</filter>"+
                       "</entity>"+
                       "</fetch>";

            //build grid layout
            var layoutXml = "<grid name='resultset' object='1' jump='fullname' select='1' icon='1' preview='1'>"+
                             "<row name='result' id='contactid'>"+
                               "<cell name='fullname' width='300'/>"+
                              "<cell name='new_field1' width='150'/>"+
                              "<cell name='new_field2' width='150'/>"+
                              "</row>"+
                           "</grid>";

    (here is your code that you suggested me to use)

    document.getElementById("lookup2").disableViewPicker = 0;
    Xrm.Page.getControl("lookup2").addCustomView(viewId, entityName, viewDisplayName, fetchXml, layoutXml, true);   
    document.getElementById("lookup2").disableViewPicker = 1;

    do you think the fetchxml or layoutxml need changes..

    Thanks.

    Gary.

    Thursday, August 8, 2013 4:30 AM
  • Hi Gary,

    The fetchXml and the layoutXml seems to be fine.

    Let me understand it correctly.

    "everything works fine until i save the form, the lookup2 which am setting to the form is going empty."

    As per my understanding, the steps happening are given below; Please mark the statement from where the problem is happening:

    1. The lookup field is clicked,

    2. The grid displays correctly,

    3. The value in the field gets selected,

    4. The selected value gets filled up in the lookup field after clicking the ok button of the custom view popup window.

    5. The form does not saves the value of the Lookup field that was returned from the custom view.

    Regards,


    Anubhav Bajpai

    Thursday, August 8, 2013 5:19 AM
  • Did you check if there is no other code which making this lookup empty ??

    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.

    Thursday, August 8, 2013 6:14 AM
    Moderator
  • Hi anubav,

    1. The lookup field is clicked---- right.
    2. The grid displays correctly----right,
    3. The value in the field gets selected---right,
    4. The selected value gets filled up in the lookup field after clicking the ok button of the custom view popup window---- right.
    5. The form does not saves the value of the Lookup field that was returned from the custom view---right

    after populating the value i select lookup2 value and it shows empty.

    Mahendar---- there is no other code on that lookup field.

    Thursday, August 8, 2013 1:00 PM
  • Hi,

    I fixed the problem. actually my fetchxml was missing one attribute that is in the layoutxml.

    Thanks for the inputs guys.

    Note- fetchxml attributes and layoutxml attributes need be same.  :)

    Thanks

    Gary

    • Marked as answer by gary_23 Thursday, August 8, 2013 2:51 PM
    Thursday, August 8, 2013 2:51 PM
  • Hi Gary,

    Great that you resolved the problem, but which attribute was missing between the fetchXml and layoutXml that you posted here.



    Anubhav Bajpai

    Friday, August 9, 2013 12:43 AM
  • It's was contactid attribute that was missing in fetchxml.. Gary
    • Edited by Bobg23 Friday, August 9, 2013 1:35 AM
    Friday, August 9, 2013 1:34 AM