Quantcast
Channel: CRM Development forum
Viewing all articles
Browse latest Browse all 8223

Close a Form from a function not working

$
0
0

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?




Viewing all articles
Browse latest Browse all 8223

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>