locked
Close a Form from a function not working RRS feed

  • Question

  • I am creating a function that will test to see if a Record is being created outside of a Parent or not, but the function cannot directly close the form:

    Calling Function

          TestifParent("new_accountid", "Account:);

    ...

    function TestifParent(getField, getFieldName)
    {
       if (Xrm.Page.ui.getFormType() != 1)   // Only for newly created forms
          { return null; }
       if ( Xrm.Page.getAttribute(getField).Value() === null )
          {  
             alert( getFieldName + " is missing. Please create this Record within the " + getFieldName + " Record." );
             var attributes = Xrm.Page.data.entity.attributes.get();  
             for (var i in attributes)
                { attributes[i].setSubmitMode("never"); }
             Xrm.Page.ui.close();  // <--- This won't close the Form
          }

    }

    If I change the Code to this, it closes:

    Calling Function:

       var Check = TestifParent("new_accountid", "Account");
       if ( Check == "Close" )
          { Xrm.Page.ui.close(); }  //  <---   This will close the Form

    ...

    function TestifParent(getField, getFieldName)
    {
       if (Xrm.Page.ui.getFormType() != 1)   // Only for newly created forms
          { return null; }
       if ( Xrm.Page.getAttribute(getField).Value() === null )
          {  
             alert( getFieldName + " is missing. Please create this Record within the " + getFieldName + " Record." );
             var attributes = Xrm.Page.data.entity.attributes.get();  
             for (var i in attributes)
                { attributes[i].setSubmitMode("never"); }
             return "Close";
          }
       return "Okay";
    }

    Thoughts?



    Thursday, June 19, 2014 3:47 PM

Answers