Errors related to "MasterTaskInfo" and "VariationMasterTask" when saving purchase document in V10 via API

1

When attempting to save a purchase document with the following code on a V10 DEMO database with an external application ...

        var documento = new CmpBE100.CmpBEDocumentoCompra();
        documento.Tipodoc = "VGR";
        documento.Serie = "A";
        documento.Entidade = "F0001";
        documento.TipoEntidade = "F";
        ErpEngine.Compras.Documentos.PreencheDadosRelacionados(documento);
        documento.NumDocExterno = "A-1234";
        documento.DataDoc = DateTime.Today;
        documento.DataIntroducao = DateTime.Today;
        double qty = 10;
        string warehouseCode = "A1";
        string location = "A1";
        ErpEngine.Compras.Documentos.AdicionaLinha(documento, "A0001", ref qty, ref warehouseCode, ref location, 0, 0);
        Engine.PrimaveraEngine.ErpEngine.Compras.Documentos.CalculaValoresTotais(documento);
        string avisos = "";
        Engine.PrimaveraEngine.ErpEngine.Compras.Documentos.Actualiza(documento, ref avisos);
        Debug.WriteLine (avisos);

... the method Updates () throws an exception:

  

System.Exception     HResult = 0x80131500     Message = Error integrating the Document into the Inventory.   One or more validation errors were detected during model generation:   Spring.Inventory100.Entities.MasterTaskInfo:: EntityType 'MasterTaskInfo' has no key defined. Set the key for this EntityType.   Spring.Inventory100.Entities.VariationMasterTask:: EntityType 'VariationMasterTask' has no key defined. Set the key for this EntityType.   MasterTaskInfoes: EntityType: EntitySet 'MasterTaskInfoes' is based on type 'MasterTaskInfo' that has no keys defined.   VariationMasterTasks: EntityType: EntitySet 'VariationMasterTasks' is based on type 'VariationMasterTask' that has no keys defined.     Source = CMPBS100     StackTrace:      at CmpBS100.CmpBSCompras.Updates (CmpBEDocumentoCompra com clsDocCompra, String & strAvisos, String & IdDocLiqRet, String & IdDocLiqRetGar)      at CmpBS100.CmpBSCompras.Actualiza (CmpBEDocumento compra clsDocCompra, String & strAvisos)      at Moving2U.PrimaveraEngine100.Engine.PrimaveraEngine.Test () in C: \ dev \ m2uvso \ m2uLogistics \ Legacy \ V4.5-dev \ Integration \ M2uLogisitcsIntegration.PrimaveraV10 \ Moving2U.PrimaveraEngine100 \ Engine \ Engine.cs: line 494   ...   Inner Exception 1:   ModelValidationException: One or more validation errors were detected during model generation:   Spring.Inventory100.Entities.MasterTaskInfo:: EntityType 'MasterTaskInfo' has no key defined. Set the key for this EntityType.   Spring.Inventory100.Entities.VariationMasterTask:: EntityType 'VariationMasterTask' has no key defined. Set the key for this EntityType.   MasterTaskInfoes: EntityType: EntitySet 'MasterTaskInfoes' is based on type 'MasterTaskInfo' that has no keys defined.   VariationMasterTasks: EntityType: EntitySet 'VariationMasterTasks' is based on type 'VariationMasterTask' that has no keys defined.

If you create a document of this type in the Spring itself with the same data, the document is written without errors. Does the same code work in Spring V8 / V9, is it missing something in the code or in the company settings?

    
asked by anonymous 26.07.2018 / 19:32

2 answers

3

Good evening

A direct integration into the purchases should work without problems. I tested the example below with the latest release available and it worked fine.

This code is called direct to motor or calls a specific component.

using ErpBS100;
using CmpBE100;
using StdBE100;
using System;
using static StdBE100.StdBETipos;

namespace Invoice.V10.Sample
{
    class Invoice
    {
        static void Main(string[] args)
        {
            CreateInvoice();
            Console.ReadKey();
        }

        static void CreateInvoice()
        {
            StdBETransaccao objStdTransac = new StdBETransaccao();
            ErpBS bso = new ErpBS();
            string strAvisos = string.Empty;
            bool blnModoPrimario = true;

            Console.ForegroundColor = ConsoleColor.White;
            Console.Write("Open API.... \n");

            bso.AbreEmpresaTrabalho(EnumTipoPlataforma.tpEmpresarial, "Demo10", "", "", objStdTransac, "Default", blnModoPrimario);

            if (bso != null)
            {
                CmpBEDocumentoCompra invoice = new CmpBEDocumentoCompra();

                Console.Write("TipoDoc: ");
                var tipoDoc = Console.ReadLine();
                invoice.Tipodoc =tipoDoc;

                Console.Write("Entidade: ");
                var entidade = Console.ReadLine();
                invoice.Entidade = entidade;

                Console.Write("Serie: ");
                var serie = Console.ReadLine();
                invoice.Serie=serie;

                Console.Write("Artigo: ");
                var artigo = Console.ReadLine();

                invoice.TipoEntidade = "F";

                Random rnd = new Random();
                invoice.NumDocExterno = rnd.Next(1000).ToString();

                try
                {
                    Console.Write("A gravar o documento...\n");
                    bso.Compras.Documentos.PreencheDadosRelacionados(invoice);
                    bso.Compras.Documentos.AdicionaLinha(invoice, artigo);
                    bso.Compras.Documentos.Actualiza(invoice, ref strAvisos);

                    if (strAvisos.Length > 0)
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.Write($"Error writing document. \n { strAvisos};");
                    }
                    else
                    {
                        Console.ForegroundColor = ConsoleColor.Green;
                        Console.Write("Document saved with success. \n");
                    }

                }
                catch (Exception ex)
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.Write($"Unable to save document. \n {ex.Message};");
                }
                finally
                {
                    Console.ResetColor();
                    bso.FechaEmpresaTrabalho();
                }
            }
        }
}
    
26.07.2018 / 23:55
2

The project where this code example was running is a new class library, in the context of a solution that includes our base classes integrating our system with ERP, but which was invoked by a test application console already with several years, that had changed to the target framework 4.7.1.

After confirming that the example provided by Sergio worked on a new project, I added a new console application in the same solution, and added the same references to the previous one, and both the example of Sergio Sereno and mine already passed to work. So I tested integrate a receipt of a vendor database made on a PDA in V10, and it already worked as expected.

I suspect that the origin of the problem in the original application console might be related to having changed the target framework, but not having updated the previously added references, notably the Entity Framework.

This gives the information to others who may be migrating "in place" previous Spring integration projects.

    
27.07.2018 / 16:17