SharePoint 2013 从查询字符串中设置依赖组合框字段

SharePoint 2013 Set Dependent Combo box field from Query String

我有一个与新项目表单上的父列表相关联的组合框字段。当我使用信息路径自定义表单并添加查询字符串 Web 部件时,该字段不可用。如果我不自定义它,使用默认的新项目形式,它变得可用,但它没有设置值。

我在查询字符串中设置了查询参数。这工作正常。我尝试了 javascript 解决方案,但它们似乎适用于 SP 2010,因为 SP 2013 完全破坏了字段名称。

根据https://knowledge.hubspot.com/articles/kcs_article/forms/can-i-auto-populate-form-fields-through-a-query-string,无法设置此依赖字段。不过,我仍然需要设置字段。

首先,使用 JavaScript 获取特定的查询字符串,然后使用 Jquery:

将该值作为选项添加到组合框
<script type="text/javascript" src="http://code.jquery.com/jquery-1.12.4.js"></script>
<script type="text/javascript">
jQuery(document).ready(function () {
    var test= $.getParameterByName("Source");
    console.log(test);
    $("select[title='Combo']").append($('<option>', {
    value: 1,
    text: test
}));

});
$.getParameterByName = function (name) {
            name = name.replace( /[\[]/ , "\\[").replace( /[\]]/ , "\\]");
            var regexS = "[\?&]" + name + "=([^&#]*)";
            var regex = new RegExp(regexS);
            var results = regex.exec(window.location.search);
            if (results == null)
                return "";
            else
                return decodeURIComponent(results[1].replace( /\+/g , " "));
        };
</script>

这部分用于选择一个已经存在的值。我想我会 post 为遇到此问题的任何其他人提供它。把Jerry_SPWX的答案和这个结合起来。

console.log($("select[title='Combo']")[0].options);
var el = $("select[title='Combo']")[0];
for(var i=0; i<el.options.length; i++) {
    if ( el.options[i].text == test ) {
      el.selectedIndex = i;
      console.log(el.selectedIndex);
      break;
    }
  }