Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/321.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# crm:创建唯一发票_C#_Dynamics Crm 2011 - Fatal编程技术网

C# crm:创建唯一发票

C# crm:创建唯一发票,c#,dynamics-crm-2011,C#,Dynamics Crm 2011,你能帮我做一下crm 2011吗 我需要从我们系统的另一个进口发票。(很简单) 我是预检电话事件 因此,在第二次调用时,方法创建另一项(如INV-01157-F4C5F5) 对我来说,这是不可接受的 如何检查发票号码?类似于如果我在系统中有此号码,我将跳过记录。您可以创建对组织服务的查询,要求搜索具有给定号码的发票,如果结果不为空,则跳过创建发票 您的代码可能如下所示: private void CreateInvoice(Invoice _invoice) { IOrganizatio

你能帮我做一下crm 2011吗 我需要从我们系统的另一个进口发票。(很简单)

我是预检电话事件

因此,在第二次调用时,方法创建另一项(如INV-01157-F4C5F5

对我来说,这是不可接受的


如何检查发票号码?类似于如果我在系统中有此号码,我将跳过记录。

您可以创建对
组织服务的查询,要求搜索具有给定号码的发票,如果结果不为空,则跳过创建发票

您的代码可能如下所示:

private void CreateInvoice(Invoice _invoice)
{
    IOrganizationService _service = GetCRMService();

    // Getting all invoices with given number 
    var filter = new FilterExpression();
    filter.AddCondition(e_Invoice.InvoiceNumber, ConditionOperator.Equal, _invoice.Id.ToString());

    var query = new QueryExpression("invoice")
    {
        ColumnSet = new ColumnSet(true),
        Criteria = filter,
        Distinct = true
    };

    // Executing query
    var invoices = (EntityCollection)_service.RetrieveMultiple(query);

    if (invoices.Entities.Count == 0)
    {
        // Creating new invoice
        Entity entity = new Entity("invoice");

        entity[e_Invoice.InvoiceNumber] =  _invoice.Id.ToString();
        entity[e_Invoice.CustomerId] = new EntityReference("account", new Guid("6209A6AD-43B6-E211-A99D-005056A51C55"));

        _service.Create(entity);
    }
}

您可以创建对
OrganizationService
的查询,要求搜索具有给定编号的发票,如果结果不为空,则跳过创建发票

您的代码可能如下所示:

private void CreateInvoice(Invoice _invoice)
{
    IOrganizationService _service = GetCRMService();

    // Getting all invoices with given number 
    var filter = new FilterExpression();
    filter.AddCondition(e_Invoice.InvoiceNumber, ConditionOperator.Equal, _invoice.Id.ToString());

    var query = new QueryExpression("invoice")
    {
        ColumnSet = new ColumnSet(true),
        Criteria = filter,
        Distinct = true
    };

    // Executing query
    var invoices = (EntityCollection)_service.RetrieveMultiple(query);

    if (invoices.Entities.Count == 0)
    {
        // Creating new invoice
        Entity entity = new Entity("invoice");

        entity[e_Invoice.InvoiceNumber] =  _invoice.Id.ToString();
        entity[e_Invoice.CustomerId] = new EntityReference("account", new Guid("6209A6AD-43B6-E211-A99D-005056A51C55"));

        _service.Create(entity);
    }
}