다음을 통해 공유


수신 대화 레코드 검색 및 열기

이 튜토리얼에서는 Dynamics 365 채널 통합 프레임워크 API를 사용하여 수신 통화에서 Dynamics 365에서 레코드를 검색하고 여는 방법을 알아보세요.

이 샘플은 4가지 시나리오를 다룹니다.

  • 고객의 연락처 번호가 Dynamics 365의 하나의 레코드와 일치합니다. 레코드는 searchAndOpenRecords API를 사용하여 검색됩니다.

  • 고객의 연락처 번호가 Dynamics 365에서 동일한 엔터티 유형의 여러 레코드와 일치합니다. 레코드는 searchAndOpenRecords API를 사용하여 검색됩니다.

  • 고객의 연락처 번호가 Dynamics 365에서 여러 엔터티 유형의 여러 레코드와 일치합니다. 계정 엔티티 및 연락처 엔티티 레코드에서 수신 전화의 연락처 번호를 검색한 다음 콘솔에 검색 결과를 표시합니다.

  • 고객의 연락처 번호가 Dynamics 365의 어떤 레코드와도 일치하지 않으므로 빈 결과를 검색하여 연 다음 createRecord API를 사용하여 고객에 대한 새 레코드를 생성합니다.

전제 조건

  • Visual Studio 2017.
  • 샘플 앱을 Azure에 게시하려면 유효한 Microsoft Azure 구독이 필요합니다.

중요

이 튜토리얼은 간단한 통신 위젯 구축 시작하기의 연속입니다. Dynamics 365 채널 통합 프레임워크에서 호스팅할 수 있는 간단한 Hello World! 위젯을 아직 만들지 않은 경우 해당 위젯을 먼저 읽어 보는 것이 좋습니다.

위젯 구축하기

  1. Visual Studio 2017에서 간단한 통신 위젯 만들기 시작하기에서 설명한 단계를 사용하여 만든 기본 위젯을 엽니다.

  2. Index.cshtml 파일을 열고 파일의 코드를 아래 제공된 코드로 바꿉니다.

    솔루션 탐색기에서 Index.cshtml 파일을 엽니다.

<!DOCTYPE html>
<style>
    .button {
        background-color: #4FAFCD;
        border: none;
        color: white;
        padding: 15px 32px;
        text-align: center;
        text-decoration: none;
        display: inline-block;
        font-size: 16px;
        margin: 4px 2px;
        cursor: pointer;
        height: 55px;
        width: 200px;
        font-size: 12px;
    }
</style>

<html>
<body>
    <br /><br />
    <!--Replace <ORG-URL> in the script tag below with the URL of your Dynamics 365 instance -->
    <script type="text/javascript" src="<ORG-URL>/webresources/Widget/msdyn_ciLibrary.js" data-crmurl="<ORG-URL>" data-cifid="CIFMainLibrary">
    </script>
    <script>

        function singlematch() {
            // The customer phone number matches one contact in Dynamics 365
            var contactno = "555-5555"; // The contact number to be searched
            var entityname = "account"; // Entity type whose records are to be searched

            Microsoft.CIFramework.searchAndOpenRecords(entityname, "?$select=name,telephone1&$filter=telephone1 eq '" + `${contactno}` + "'" + "&$search=" + `${contactno}`, false).then(
                function success(result) {
                    res = JSON.parse(result);
                    // Display the name and telephone number of the retrieved contact on the console
                    console.log(`Record values: Name: ${res[0].name}, Telephone number: ${res[0].telephone1}`);
                },
                function (error) {
                    console.log(error.message);
                }
            );
        }

        function multiplematchsingletype() {
            // More than one contacts are matched with same phone number
            // Search and show search results on console
            var contactno = "555-5555"; // The contact number to be searched
            var entityname = "account"; // Entity type whose records are to be searched

            Microsoft.CIFramework.searchAndOpenRecords(entityname, "?$select=name,telephone1&$filter=telephone1 eq '" + `${contactno}` + "'" + "&$search=" + `${contactno}`, false).then(
                function success(result) {
                    res = JSON.parse(result);
                    count = Object.keys(res).length;
                    // Print all the retrieved records on the console
                    while (count >= 1) {
                        console.log(`Record values: Name: ${res[count - 1].name}, Telephone number: ${res[count - 1].telephone1}`);
                        count = count - 1;
                    }
                },
                function (error) {
                    console.log(error.message);
                }
            );
        }

        function multiplematchmultipletype() {
            // More than one records are matched with the same phone number. These records belong to different entity types
            // Search and show search results on console
            var contactno = "555-5555"; // The contact number to be searched

            // Set the value of searchOnly parameter to True if you only want to get results of the search as a promise result and not open the record or search page. More information: https://learn.microsoft.com/dynamics365/customer-engagement/developer/channel-integration-framework/reference/microsoft-ciframework/searchandopenrecords#parameters.
            Microsoft.CIFramework.searchAndOpenRecords("contact", "?$select=fullname,telephone1&$filter=telephone1 eq '" + `${contactno}` + "'"  + "&$search=" + `${contactno}`, true).then(
                function success(result) {
                    res = JSON.parse(result);
                    count = Object.keys(res).length;
                    // Print all the retrieved records on the console
                    while (count >= 1)
                    {
                        console.log(`Contact entity record values: Name: ${res[count - 1].fullname}, Telephone number: ${res[count-1].telephone1}`);
                        count = count - 1;
                    }
                }, function (error) {
                    console.log(error.message);
                });

            Microsoft.CIFramework.searchAndOpenRecords("account", "?$select=name,telephone1&$filter=telephone1 eq '" + `${contactno}` + "'"  + "&$search=" + `${contactno}`, true).then(
                function success(result) {
                    res = JSON.parse(result);
                    count = Object.keys(res).length;
                    // Print all the retrieved records on the console
                    while (count >= 1)
                    {
                        console.log(`Contact entity record values: Name: ${res[count - 1].name}, Telephone number: ${res[count - 1].telephone1}`);
                        count = count - 1;
                    }
                }, function (error) {
                    console.log(error.message);
                });
        }

        function nomatch() {
            // Search and show empty search results
            // Create new contact based on the details of the incoming call
            // Associate new contact to session
            var contactno = "000040000025"; // The contact number to be searched
            var callername = "Contoso Ltd."; 

            Microsoft.CIFramework.searchAndOpenRecords("account", "?$select=name,telephone1&$filter=telephone1 eq '" + `${contactno}` + "'"  + "&$search=" + `${contactno}`, false).then(
                function success(result) {
                    res = JSON.parse(result);
                    console.log(res);
                    // Check if the JSON response returned by the request is empty
                    if (Object.keys(res).length == 0) {
                        console.log("No records with contact number as " + contactno);
                        console.log("Creating a new Account record");

                        // Creating new Account record
                        var entityLogicalName = "account";
                        var data = {
                            "name": callername,
                            "telephone1": contactno
                        }
                        var jsondata = JSON.stringify(data);

                        // use createRecord API to create a new entity record
                        Microsoft.CIFramework.createRecord(entityLogicalName, jsondata).then(
                            function success(result) {
                                res = JSON.parse(result);
                                // Print the AccountID of the created Account record on the console
                                console.log("Account record created with ID: " + res.id);
                            })
                    }
                    else {
                        console.log(`Record values: Name: ${res[0].name}, Telephone number: ${res[0].telephone1}`);
                    } 
                },
                function (error) {
                    console.log(error.message);
                }
            );
        }
    </script>

    <button class="button" type="button" onclick="singlematch()">One matching record</button><br /><br />
    <!-- singlematch() method is invoked when you click on "One matching record" button. This returns the record which has the same phone number as the number of the incoming call -->
    <button class="button" type="button" onclick="multiplematchsingletype()">More than one matching records of same type</button><br /><br />
    <!-- multiplematchsingletype() method is invoked when you click on "More than one matching records of same type" button. This returns the all records of one particular entity type, which have the same phone number as the number of the incoming call -->
    <button class="button" type="button" onclick="multiplematchmultipletype()">More than one matching records of different types</button><br /><br />
    <!-- multiplematchmultipletype() method is invoked when you click on "More than one matching records of different types" button. This returns the all records of mutliple entity types, which have the same phone number as the number of the incoming call -->
    <button class="button" type="button" onclick="nomatch()">No match</button><br /><br />
    <!-- nomatch() method is invoked when you click on "No match" button. If there is no existing record with the same phone number as the number of the incoming call, it uses the details of the incoming call to create a new record -->

    
</body>
</html>

위젯 게시 및 구성하기

위젯 게시 및 구성하기에 설명된 단계에 따라 위젯을 게시합니다. 게시된 위젯은 다음과 같아야 합니다.

통합 인터페이스 앱에 게시된 샘플 위젯입니다.

참조 항목

간단한 통신 위젯 구축
소프트폰 통합을 위한 샘플 코드
자주 묻는 질문