This relates to SharePoint 2013 Online.

On my home page I have a SEWP which determines if currentUser has registered some details we need. If not then open a ModalDialog window displaying a form to submit the details.

I've removed the ajax calls in code below, as they're not an issue, so the pertinent stuff is:

<script type="text/javascript">
var sitePath = '/teams/company/site/subsite1/subsite2';

function isUserRegistered() {
    var login = _spPageContextInfo.userLoginName;

    // currentUser is not registered so display modal...

                var options = {
                    url: sitepath + '/Lists/Users/Register.aspx?IsDlg=1",
                    width: 800,
                    height: 600,
                    showClose: true,
                    title: "Welcome " + firstName + ",",
                    dialogReturnValueCallback: dialogResult
                SP.SOD.execute('sp.ui.dialog.js', 'SP.UI.ModalDialog.showModalDialog', options);


function dialogResult(result, response) {
        case SP.UI.DialogResult.cancel:
            console.log('result = cancel'); break;
        case SP.UI.DialogResult.invalid: 
            console.log('result = invalid'); break;
        case SP.UI.DialogResult.ok:
            alert('OK'); break;

The Register.aspx was created in SPD 2013 by navigating to the All Files > Lists > Users and then choosing File > ASPX file. I added my html and script for handling Save button click:

<!DOCTYPE html>
<%@ Page Language="C#" %>
<%@ Register tagprefix="SharePoint" namespace="Microsoft.SharePoint.WebControls" assembly="Microsoft.SharePoint, Version=, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<html dir="ltr" xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">
<meta name="WebPartPageExpansion" content="full" />
<meta http-equiv="X-UA-Compatible" content="IE=10" />
<script type="text/javascript" src="/_layouts/15/sp.runtime.js"></script>
<script type="text/javascript" src="/_layouts/15/sp.js"></script>
<SharePoint:CssRegistration Name="default" runat="server"/>

<script type="text/javascript">
    function saveDetails(CellNo, Company, CarReg, AccessCard) {
        var results = {
            CellNo: CellNo.value,
            Company: Company.value,
            CarReg: CarReg.value,
            AccessCard: AccessCard.value
        SP.UI.ModalDialog.commonModalDialogClose(SP.UI.DialogResult.ok, results);
<form id="userInfo" runat="server">
    <div style="background-color:lightgray;">
            <br />
            <h3>Cell no.: <input name="CellNo" type="text" /></h3>
            <h3>Company: <input name="Company" type="text" value="Tesco" /></h3>
            <h3>Car registration: <input name="CarReg" type="text" /></h3>
            <h3>Tesco access card number: <input name="AccessCard" type="text" /></h3>
            <br />
            <button type="submit" onclick="return saveDetails(CellNo, Company, CarReg, AccessCard)">Save</button>
            <br />

The problem I am having is that when I click 'Save' the page complains that SP is undefined.

So how can I reference SP.js in order to close modal and pass back results to parent page? (Or alternative method if it achieves the same objective.)


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.