创建或查询与联系人相关联的Dynamics 365任务

时间:2019-01-15 00:44:22

标签: node.js dynamics-crm microsoft-dynamics dynamics-crm-webapi

在Node.js中使用dynamics-web-api

我想获得(最终创建)与MS Dynamics 365中的潜在客户或联系人相关的任务。使用js。但是,我不知道如何将联系人ID与任务ID匹配。我该如何匹配或查看与之相关的事物?

var dynamicsWebApi = MyDynamicsContextGetter();

var filters = `emailaddress1 eq '${email.trim()}' 
    and firstname eq '${firstName.trim()}'
    and lastname eq '${lastName.trim()}'`;

dynamicsWebApi.retrieveRequest({
    collection: "contacts",
    select: ["fullname", "emailaddress1", "company"],
    filter: filters,
    top: 1,
    count: true
}).then(function (response) {
    var count = response.oDataCount;
    var records = response.value;
    var topContactId = records.length > 0 ? records[0].contactid : null;
    if(count !== 0) {
        dynamicsWebApi.retrieveRequest({
            collection: 'tasks',
            filter: 'regardingobjectid_contact/contactid eq ' + topContactId,
            top: 5,
            count: true
        }).then(function(response) {


        // THIS VALUE IS ALWAYS 0 FOR ME 
        console.log("response", response.oDataCount); 


    }).catch(function (error) {
        res.send(500);
    });
}
});

1 个答案:

答案 0 :(得分:0)

一切正常,除了下一行,请尝试以下操作:

        filter: "regardingobjectid_contact/contactid eq guid'" + topContactId + "'",