使用Xrm.Navigation.openWebResource()之后如何从Web资源中获取表单数据

时间:2018-11-03 07:46:11

标签: javascript dynamics-crm dynamics-crm-online dynamics-365 dynamics-crm-365

我有一个Web资源,只需单击以下按钮即可打开它:

var windowOptions = { height: 400, width: 50 };
Xrm.Navigation.openWebResource("DCWIMS_/html/datepicker.html", windowOptions);

我在html webresource中有一个小的输入字段(您可以猜到,它是一个日期时间字段)。我的问题是,关闭表单后如何获取字段数据?我从函数中调用了上面的代码

function Cancel() {

   
    var contract_id = Xrm.Page.data.entity.getId();
    var contract_guid = contract_id.replace(/[{}]/g, "");
    
    var windowOptions = { height: 400, width: 50 };
    Xrm.Navigation.openWebResource("DCWIMS_/html/datepicker.html", windowOptions);

    //need field data to be returned so I can set a field in the form to its value
    var datefield = ??

    formContext.getAttribute("new_cancellationdate").setValue(datefield);


    //Set the stage to send enquiry letter
    XrmSvcToolkit.setState({
        id: Xrm.Page.data.entity.getId(),
        entityName: "new_contract",
        stateCode: 1,
        statusCode: 100000002, //Cancelled
        async: false
    });
    
    }

这是html网络资源:

<!doctype html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <script src="ClientGlobalContext.js.aspx" type="text/javascript"></script>
    <title>Set Cancellation Date</title>

    <script>

        

        

        window.onload = function () {
            document.getElementById('party-time').onsubmit = function () {

                var date = document.getElementById('party-time').value;
                webResourceData.windowCallback(date);

                // You must return false to prevent the default form behavior
                return false;
            };
        };

        function Quit() {
            window.close();
        }

        


    </script>
</head>

<body>

    
 
  <fieldset>
    <legend>Cancellation Date</legend>

    <div>
        <label for="party-time">Date/time:</label>
        <input type="datetime-local" id="party-time"
               name="party-time" value=""
               min="" max="" />
        <button type="submit" onclick="Quit()">Submit </button>
    </div>


</fieldset>
 
 
</body>
</html>

1 个答案:

答案 0 :(得分:1)

尝试一下。不用从webresource返回值到父窗口,而是从HTML本身分配值。

    function Quit() {
            window.opener.Xrm.Page.getAttribute("new_cancellationdate").setValue(document.getElementById('party-time').value);

            window.close();
    }