I need to be able to do next: When a user fulfilling a form the user email needed to pass automatically. It says logged in user email automatically fetched.

How can I do that in SharePoint Online iFrame? I need that code for iFrame.


You can get the current user email using the client context. Below code is in JSOM.

<script type="text/javascript">
var currentUser;
function init(){
    this.clientContext = new SP.ClientContext.get_current();
    this.oWeb = clientContext.get_web();
    currentUser = this.oWeb.get_currentUser();
    this.clientContext.executeQueryAsync(Function.createDelegate(this,this.onQuerySucceeded), Function.createDelegate(this,this.onQueryFailed));
function onQuerySucceeded() {

function onQueryFailed(sender, args) {
    alert('Request failed. \nError: ' + args.get_message() + '\nStackTrace: ' + args.get_stackTrace());
<div>Current Logged User:
     <span id="userEmail"></span>

Note: you have to include jquery plug-in.

  • Hello, thanks for you response. Do I need to add exactly this code as a script in the web part?After that it will work for the iFrame?
    – J.U
    May 31 '17 at 15:19
  • If you are working with Sharepoint hosted apps, this will do the trick.
    – Arut
    May 31 '17 at 17:50
  • Hello Arut, I added that script to Script Editor Web Part to the iFrame Web Part. I am able to get logged in user, but the information is not passing to the iFrame. How can I pass information to the iFrame?
    – J.U
    Jun 1 '17 at 5:59
  • You can search for an element from the iframe and you can set the value using jquery. $("#iFrame_ID").contents().find("#some_Control_ID").val('your_value');
    – Arut
    Jun 1 '17 at 6:34
  • Sorry, how can I do that? I'm new learner. Maybe you can clarify little bit. Thanks in advance!
    – J.U
    Jun 1 '17 at 8:44

Your Answer

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

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