Need help with JavaScript in Nintex Forms 2010

Discussion created by dbonsma on Oct 27, 2016

I have a Document Set (call it "CustomerSet") Welcome page set up to display a related custom list (call it "CustomerNotes") as a web part, below the document set details and the documents themselves.  This CustomerNotes list is filtered using a Page Field Filter web part, on the Title field from the document set. In the CustomerNotes list, I have a field ("CustomerLookup") set up as a "Lookup" field, which does its lookup into the CustomerSet document set. This all works great.  On the "Default New Form" for the list (selected from the "Form Web Parts" dropdown menu on the ribbon) I added a Content Editor web part, and have this JavaScript added:


<script language="javascript" src="/xxxx/Style%20Library/scripts/jquery-1.9.1.js" type="text/javascript"></script>

var $j = jQuery.noConflict();

function getParameterByName(name) {
    name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
    var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
        results = regex.exec(location.search);
    return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
$j(document).ready(function() {

var rootFolder = getParameterByName('RootFolder').split('/');

if (typeof(rootFolder) != 'undefined'){
 var text1 = rootFolder[rootFolder.length-1];

 if ($j("select[Title='CustomerLookup']").length==0){
  choices = $j("input[title='CustomerLookup']").attr("choices");
  hiddenInput = $j("input[title='CustomerLookup']").attr("optHid");
         choiceArray = choices.split("|");
         for (index = 1; index < choiceArray.length; index = index + 2)
          if (choiceArray[index- 1] == rootFolder[2]){
                  $j("input[id='" +hiddenInput +"']").attr("value",choiceArray[index])  
  $j("input[Title='CustomerLookup']").parent().parent().parent().parent().css("display", "none");
 else {
  $j("select[Title='CustomerLookup'] option").filter(function() {
  return $j(this).text() == text1;
  }).prop('selected', true)
  $j("select[Title='CustomerLookup']").parent().parent().parent().css("display", "none");


The purpose of this JavaScript code is to automatically populate the CustomerLookup field in the list when I click "Add new item" on the list, within the CustomerSet welcome page.  This works great, as long as I leave the form as its default InfoPath form. 


My question is that I would like to replace the Add/Edit forms for the CustomerNotes list with a Nintex form, however I don't know if or how to get the JavaScript to still do this automatic field population when I am adding a new item. I have tried leaving the code in the Content Editor web part on the "Default New Form" web part page, but using the Nintex form rather than the InfoPath form. This doesn't generate any errors, but doesn't populate the CustomerLookup field.  I have also tried adding the code (exactly as is) to the Nintex form, in the Custom JavaScript area. This also doesn't work, but also doesn't generate any errors.


I don't know JavaScript very well, and had help writing this code initially, so I would appreciate any tips on how I might get this to work.