Solved

Capturing user data from an embedded form


Userlevel 2
Badge +7

I’m designing a form that I would like to embed on a page in SharePoint, rather than provide a link to it. But to embed a form in NAC, you have to give form access to “anyone with the form URL.” Obviously this is primarily intended for public forms where you don’t have any user data unless you explicitly ask for it on the form. I’m trying to avoid having to ask for any user data because the form will be for internal use only, accessed only by authenticated users.

I was trying to rig up a way to go and grab the user data from the NAC instance, something like this:

  1. On the form, use the newGuidAsString function to generate a unique identifier.
  2. Use that unique identifier to Set instance name in the workflow.
  3. Somehow find that single instance in NAC and grab the user data from it.

I thought maybe the Get workflow instances function would do the trick, but you can’t set conditions in it (such as “when NAC instance name = unique identifier”) and it doesn’t seem to capture user data anyway.

I’m guessing there’s not really a way to do this and I’m just gonna have to bite the bullet and ask for user data in the form. Really, all I need is their email address. (On my authenticated workflows, I always capture user data using Azure AD functionality so that the user doesn’t have to enter any of that info.) And assuming there isn’t a way to do it, can someone explain why authenticated forms can’t be embedded?

 

icon

Best answer by Jake 13 May 2024, 11:13

View original

9 replies

Userlevel 4
Badge +15

Because your using an unauthhenticated form...user data will not be available to fetch in NAC. Nintex doesnt capture data when thats checked...its like an anonymous Microsoft Form if you're familiar. 

 

Your only option is to ask for an email. 

Userlevel 4
Badge +15

But following because i wanna know the same thing! 

Userlevel 5
Badge +13

Hi @DavidAD@brandiwoodson 

 

Authenticated forms are not supported because we cannot ensure end to end validity on a domain we cannot validate directly, CORS will not allow it, as frustrating as it is the alternative of allowing it can be a security risk.


It is possible to pass values into the embedded form but it requires using script editor web part instead of the standard embed form, see below my notes on this. 
 

Step 1: Enable custom scripting

Before you can add custom script web parts, ensure that custom scripting is enabled on your SharePoint site:

  1. Go to the SharePoint Admin Center.
  2. In the left-hand navigation, select "Settings".
  3. Under "Custom Script", ensure that "Allow users to run custom script on personal sites" and "Allow users to run custom script on self-service created sites" are enabled. This change might take up to 24 hours to take effect.

Step 2: Install the modern script editor web part

The Modern Script Editor Web Part is a custom SPFx (SharePoint Framework) solution developed by the community. Follow these steps to install it:

  1. Download the SPFx solution package:

    1. Go to the GitHub repository for the Modern Script Editor and download the latest release.

  2. Upload the package to the app catalog:

    1. Go to your SharePoint App Catalog site. If you don't have one, you need to create it via the SharePoint Admin Center.

    2. Upload the .sppkg file you downloaded to the "Apps for SharePoint" library.

    3. When prompted, ensure you select "Make this solution available to all sites in the organisation" and click "Deploy".

Step 3: Add the modern script editor web part to your page

  1. Navigate to the SharePoint page where you want to add the script.
  2. Click "Edit" to modify the page.
  3. Click the "+" button to add a new web part.
  4. Search for "Script Editor" in the web part selection pane and add it to the page.

Step 4: Embed the form with your script

  1. Once the Script Editor web part is added to the page, click the "Edit" button on the web part.

  2. A text box will appear where you can paste your script. Here’s an example script to dynamically set the iframe URL and embed the form:
     

    <script type="text/javascript">
    document.addEventListener("DOMContentLoaded", function() {
    // Get the current user login name
    var currentUser = _spPageContextInfo.userLoginName;

    // Construct the Nintex form URL with the current user's login name
    var formId = "[EXAMPLE-7996-4f6f-bc71-900b558dc870]";
    var tenancy = "[Your Tenant].workflowcloud.com";
    var formUrl = `https://${tenancy}/embedform/iframe?id=${formId}&tenancy=${tenancy}&user=${currentUser}`;

    // Set the iframe's src attribute to the constructed URL
    var iframe = document.getElementById(`ntxFormContainer-${formId}`);
    if (iframe) {
    iframe.src = formUrl;
    }

    // Load the Nintex embed script
    var script = document.createElement("script");
    script.src = `https://${tenancy}/embedform/iframe/ntx-embed-iframe.js`;
    script.setAttribute("data-id", `ntxFormContainer-${formId}`);
    document.head.appendChild(script);
    });
    </script>

    <iframe id="[Your form ID]" scrolling="no" style="width:100%; border:none;" height="100%"></iframe>
  3. In the code you will need to replace the placeholders with the embed code you can get from automation cloud on a publish, they are:
    1. formId marked by [EXAMPLE-7996-4f6f-bc71-900b558dc870]
    2. tenancy marked by [Your Tenant]
    3. id marked by [Your form ID] (yes this is the same as formId)
    4. note that the current user is being passed in from the _spPageContextInfo.userLoginName function
  4. Ensure that the published form has a query string parameter variable set up
    1. In your Nintex form open the variable and create a new variable naming how you like
    2. Insert the following function getQueryStringParameter("user") as in the code we are passing current user as user as a query string:

       

    3. You can use a rule to fill out any form fields you want with the parameter.
       
    4. Save and publish all changes.

       

  5. After that you should see the newly embedded form with the current user

 

Userlevel 2
Badge +7

Thank you, @brandiwoodson and @Jake, for your answers. As devilishly clever as that solution is, @Jake, I don’t think it’s worth attempting - at least not in this case. I’ll keep it in mind for future use, though.

Userlevel 4
Badge +15

@Jake  Thanks for the alternative instructions!

Badge +3

@Jake

Thanks so much for sharing this, this is exactly what I needed, however I’m stil running into a couple of issues.

My form has an external datasource, the query needs a parameter that I want to pass dynamically to the embedded form via getQueryStringParameter. 

I’m still figuring out the best way to pass the parameter to the form (I get this error Error: Unable to receive QueryString from Host via PostMessage)

 

But even if I get the parameter/querystring part to work, I’m always getting an error “Data failed to load” on the form. 

 

After inspecting the network calls with dev tools, I can see a POST call to the URL below that’s returning a http 405 The resource doesn't support specified Http Verb

https://gbo-app-znc.nintex.io/assets/embedform/iframe/undefined/datasources/{someguid}/execute

 

Do you know if this CORS related ? I’m embedding the form in an Umbraco project, my test was done on dev machine (localhost). 

 

Userlevel 5
Badge +13

Hi @etienneg 

Accessing data sources is not something I have tested using this method, I will see if I can set something up to test for you.

Jake 

Badge +3

Hi @etienneg 

Accessing data sources is not something I have tested using this method, I will see if I can set something up to test for you.

Jake 

@Jake 

The doc says it’s not supported :( 

https://help.nintex.com/en-US/nwc/Content/Dashboard/DataSources.htm

This is a bit of set back for my use case. I really need the forms to be externally accessible but I need some kind of identification and I don’t want to ask the user for their email, ideally I want the form embedded in a web site that I can trust for identifying the users. And my forms need external data to be functional.

I will have to implement my own login component to use within the form one day, I believe it’s do able but it’ll be quite a bit of work, in the meantime I’ll just show the form in a new window and pass the id in the url parameters. far from ideal but it should be good enough for now. 

If you have any suggestion please let me know. 

Userlevel 5
Badge +13

Hi @etienneg 

I am afraid you have a few requirements that make it not viable, It should work ok in terms of data sources but not with embedded forms, if opened directly on Nintex then we can allow data sources to load. 

Another option for you would be to invite guest users and we can authenticate them directly but again opening the form will be needed. 

Jake 

Reply