1

On load of my site I check if a user is 'registered' with the site (I need specific non-SP data about them which is saved in Users list).

If not, then I show the NewForm.aspx page for Users list.

<script type="text/javascript">
  var siteuri = "/teams/technology-cell-79-new-stores-retail-implementations/testing/testlab";

   function isUserRegistered() {

    var login = _spPageContextInfo.userLoginName;

       $.ajax({
           url: siteuri + "/_api/web/lists/getByTitle('Users')/items?$filter=Title eq '" + login + "'&$select=FirstName,LastName,Email,CellNo,Company,CarReg,AccessCard",
          type: "GET",
          headers: {
            "accept": "application/json;odata=verbose"
          },
       }).success(function (data) {
         var u = data.d.results.length;

         if (u != 1) {
           var options = {
              url: "/teams/technology-cell-79-new-stores-retail-implementations/testing/testlab/Lists/Users/NewForm.aspx?Title='" + login + "'&IsDlg=1",
              width: 800,
              height: 600,
              showClose: true,
              title: "User details"
           };

        SP.SOD.execute('sp.ui.dialog.js', 'SP.UI.ModalDialog.showModalDialog', options);
    }

  }).error(function (er) {
    alert("Error getting user " + er);
  });
}

_spBodyOnLoadFunctionNames.push("isUserRegistered");

</script>

However, I want to pass the information SharePoint does know - that is loginname, email and name (albeit another ajax call to currentUser) - to the dialog and populate the form.

Edited

So, from Leopold's answer - and googling - I added below script between tag in the NewForm.aspx page:

<script type="text/javascript">
  ExecuteOrDelayUntilScriptLoaded(getArgs, "sp.js");

  function getArgs(){
  var args = SP.UI.ModalDialog.get_childDialog().get_args();
}
</script>

But when the dialog is displayed I get this error:

Sorry, something went wrong

An error occurred during the processing of /teams/technology-cell-79-new-stores-retail-implementations/testing/testlab/Lists/Users/NewForm_reg.aspx. Only Content controls are allowed directly in a content page that contains Content controls. 

If I create a new custom form with just HTML and add the script then I get error:

SP is undefined.

Am I missing something simple just to get args for modal dialog?

1 Answer 1

4

You can use the args-property in the Options for delivering Parameters into the modal dialog.

Inside the Dialog you can request them using the commonModalDialogGetArguments()function

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.