Xrm.WebApi.online.execute поможет создать уведомление - PullRequest
0 голосов
/ 01 февраля 2019

Я пытаюсь использовать execute для вызова Xrmapi.Ниже мой код.Это не выполняется должным образом, и я не понимаю, где я пропускаю.TIA

var opportunityClose={
"type":"GET",
"contentType":"application/json; charset=utf-8",
"datatype":"json",
"url":url
};
Xrm.WebApi.online.execute(new Sdk.WinOpportunityRequest(opportunityClose,4)).then(function (data, textStatus, XmlHttpRequest) {
        console.log("success getting notification activities");
        debugger;
        if (data.d.results.length == 0) // no notifications, nothing to do
            return;
        var notifications = [];

        $.each(data.d.results, function (i, notification) {

            var icon = (notification.guru_Icon ? notification.guru_Icon.Value : 770170000);
            notification.Level = Guru.Xrm.Notifications.mapIconToNotificationLevel(icon);
            notifications.push(notification);
        });
        Guru.Xrm.Notifications.AddFormNotifications(notifications);
    },
    function (XmlHttpRequest, textStatus, errorObject) {
        console.log(XmlHttpRequest);
        console.log(errorObject);
        console.log("failed to load notification activities");
    });

1 Ответ

0 голосов
/ 06 февраля 2019

В вашем коде, по-видимому, отсутствует некоторая ключевая информация, например идентификатор возможности закрытия.

Этот документ содержит пример того, как закрыть Opp через Xrm.WebApi.в сети.

Вот пример кода:

var Sdk = window.Sdk || {};
/**
 * Request to win an opportunity
 * @param {Object} opportunityClose - The opportunity close activity associated with this state change.
 * @param {number} status - Status of the opportunity.
 */
Sdk.WinOpportunityRequest = function (opportunityClose, status) {
    this.OpportunityClose = opportunityClose;
    this.Status = status;

    this.getMetadata = function () {
        return {
            boundParameter: null,
            parameterTypes: {
                "OpportunityClose": {
                    "typeName": "mscrm.opportunityclose",
                    "structuralProperty": 5 // Entity Type
                },
                "Status": {
                    "typeName": "Edm.Int32",
                    "structuralProperty": 1 // Primitive Type
                }
            },
            operationType: 0, // This is an action. Use '1' for functions and '2' for CRUD
            operationName: "WinOpportunity",
        };
    };
};


var opportunityClose = {
    "opportunityid@odata.bind": "/opportunities(c60e0283-5bf2-e311-945f-6c3be5a8dd64)",
    "description": "Product and maintainance for 2018",
    "subject": "Contract for 2018"
}

// Construct a request object from the metadata
var winOpportunityRequest = new Sdk.WinOpportunityRequest(opportunityClose, 3);

// Use the request object to execute the function
Xrm.WebApi.online.execute(winOpportunityRequest).then(
    function (result) {
        if (result.ok) {
            console.log("Status: %s %s", result.status, result.statusText);
            // perform other operations as required;
        }
    },
    function (error) {
        console.log(error.message);
        // handle error conditions
    }
);

В соответствующей заметке в этой документации описано, как использовать действие WinOpportunity через WebAPI.

Вот выдержка:

POST [Organization URI]/api/data/v9.0/WinOpportunity HTTP/1.1
Accept: application/json
Content-Type: application/json; charset=utf-8
OData-MaxVersion: 4.0
OData-Version: 4.0

{
 "Status": 3,
 "OpportunityClose": {
  "subject": "Won Opportunity",
  "opportunityid@odata.bind": "[Organization URI]/api/data/v9.0/opportunities(b3828ac8-917a-e511-80d2-00155d2a68d2)"
 }
}
...