Trouble Deleting via Page Web Service

tlarsontlarson Member Posts: 27
edited 2009-07-16 in NAV Three Tier
I'm working on learning how to use the web services in Nav 2009. So far, I can get the ReadMultiple function to work great, and then I can bind the results to a DataGridView and it shows the list/table as I expect. No problems there. I can even get it to work with filters, as the documentation shows. Here is my code:
private void FindRecords(string filterString)
{
    svc = new WindowsFormsApplication2.CustList2.CustList2_Service();
    svc.UseDefaultCredentials = true;

    List<CustList2.CustList2_Filter> filters = new List<CustList2.CustList2_Filter>();

    CustList2.CustList2_Filter myFilter = 
        new WindowsFormsApplication2.CustList2.CustList2_Filter();
    myFilter.Field = WindowsFormsApplication2.CustList2.CustList2_Fields.Name;
    myFilter.Criteria = filterString;
    filters.Add(myFilter);

    dataGridView1.DataSource =
        svc.ReadMultiple(filters.ToArray(), null, 100);                
}

That part works great. This tells me that I have the service tier set up properly and that permissions (at least for reading) are set up. At this point, I just have one windows user (the local administrator account), and it has SUPER permissions.

However, I can't get a delete to work. Here is the code for my delete button:
foreach (DataGridViewRow dr in dataGridView1.SelectedRows)
{
    CustList2.CustList2_Service svc = 
            new WindowsFormsApplication2.CustList2.CustList2_Service();
    svc.UseDefaultCredentials = true;
    CustList2.CustList2 cl = (CustList2.CustList2)dr.DataBoundItem;

    if (svc.IsUpdated(cl.Key))
    {
        throw new Exception
               ("This record has been updated since you last retrieved it: " + cl.No);
    }

    svc.Delete(cl.Key);
}
FindRecords("");

I stepped through this with a debugger, and the foreach loop hits for the record I selected, the cast to CustList2.CustList2 works properly (I can see all of the fields on the 'cl' objects just fine, including the field called 'key'). The exception is not thrown, and it runs through the svc.Delete function. However, no change to the database is made. The record is not deleted. And I can't find any kind of error.

Am I missing something here? The properties for the page I'm trying to delete a record from have Editable=Yes and DeleteAllowed=Yes.

Is there something else I have to do to get the delete to happen? Please give me some guidance on where to go to track this down. I've read through the help files, I purchased the Nav 2009 book and read through it, and I've read through the scant examples available on the internet, but I just can't figure out how to do this.

(If I create a codeunit, I can create a function called DeleteCustomer(CustomerNo) and it will delete the customer for me without any trouble. However, I'm wanting to be able to use the Delete function on the strongly typed objects available from the Page web services so that I don't have to go create a codeunit/function for every little operation I want to perform)

Thanks for your help,

Tim

Comments

  • Ravi_ThakkarRavi_Thakkar Member Posts: 392
    Hello Tim,

    First of all, Delete Function of Page Web Service Returns Boolean value. i.e. True or False.
    If in Deleting process any error exists then it will not display any kind of error on Web.
    It will just return false and will not delete the record.

    Second, if you will do Delete process by using Codeunit then it may cause Concurrency issues.
    Microsoft itself says, Codeunits are not managing the Concurrency automatically. It must be handled Manually.
    While Pages are handling the Concurrency themself.

    So, use page web services as much as possible.
    Ravi_Thakkar
    Ahmedabad, Gujarat, India
    E Mail : ravi.thakkar@hotmail.com
  • tlarsontlarson Member Posts: 27
    Ravi,

    Thanks for the tip.

    I checked the return value of the Delete function, and it is returning false. How can I dig in and figure out what's causing the Delete call to fail?

    Is there a way to debug the OnDelete trigger in the Customer table when I call delete from the web service? Or is there some other way to try to figure out why the Delete failed? Is there a way to force it to spit out an error message somewhere?

    I'm feeling very much in the dark without any kind of error message.

    Tim
  • tlarsontlarson Member Posts: 27
    I figured it out!

    After digging around for a while, I found a couple of very helpful posts on debugging Nav 2009. Clausl wrote (http://blogs.msdn.com/clausl/archive/20 ... -2009.aspx) about how to set up debugging.

    I followed his instructions to enabled debugging of the Service Tier, but ran into another problem. It was giving me some error about sp_sdidebug not existing. After reading http://blogs.ipona.com/dan/archive/2006/09/29/6699.aspx, I set the Visual Studio debugger to only try to debug Managed and Native code, and that problem went away.

    I tried again, attaching the debugger to Microsoft.Dynamics.Nav.Server.exe, et voila, it found the real problem! Here is what it told me:
    An exception of type 'Microsoft.Dynamics.Nav.Types.Exceptions.NavNCLMetadataCompileErrorException' occurred in Microsoft.Dynamics.Nav.Ncl.dll but was not handled in user code
    
    Additional information: Compilation of module 'C:\ProgramData\Microsoft\Microsoft Dynamics NAV\60\Server\MicrosoftDynamicsNavServer\module\Record5050.netmodule' failed. This could be caused by differences between binaries in your installation or your database. Ensure that all installation components are consistent and up to date. Error details: c:\ProgramData\Microsoft\Microsoft Dynamics NAV\60\Server\MicrosoftDynamicsNavServer\source\Record\Record5050.cs(2675,19) : error CS0019: Operator '<' cannot be applied to operands of type 'string' and 'string'
    c:\ProgramData\Microsoft\Microsoft Dynamics NAV\60\Server\MicrosoftDynamicsNavServer\source\Record\Record5050.cs(2675,107) : error CS0019: Operator '>' cannot be applied to operands of type 'string' and 'string'
    c:\ProgramData\Microsoft\Microsoft Dynamics NAV\60\Server\MicrosoftDynamicsNavServer\source\Record\Record5050.cs(2990,15) : error CS0019: Operator '>=' cannot be applied to operands of type 'string' and 'string'
    c:\ProgramData\Microsoft\Microsoft Dynamics NAV\60\Server\MicrosoftDynamicsNavServer\source\Record\Record5050.cs(2990,144) : error CS0019: Operator '<=' cannot be applied to operands of type 'string' and 'string'
    

    This is exactly what I needed. It turns out that my version of Table 5050 (Contact) compiles and works perfectly in C/AL and the classic client, but doesn't work so well when compiled to C#. It's a C# compiler error. And here is the first offending line of code:
    //     IF (COPYSTR(TempNamePart,STRLEN(TempNamePart),1) < 'A') OR 
    //        (COPYSTR(TempNamePart,STRLEN(TempNamePart),1) > 'Z')
    if((ALSystemString.ALCopyStr(tempNamePart, ALSystemString.ALStrLen(tempNamePart), 1)<@"A")|(ALSystemString.ALCopyStr(tempNamePart, ALSystemString.ALStrLen(tempNamePart), 1)>@"Z"))
    

    Please note that this code has been automatically generated from the C/AL code in the triggers of the table. The part commented out is the original C/AL code, and the line below it is the corresponding auto-generated C# code.

    Not I'm off to figure out how to correct this...
  • freddy.dkfreddy.dk Member, Microsoft Employee Posts: 360
    If this exception was the cause of the Delete function failing - I would assume that you would get that exception on the C# side.

    Have you tried in the roletailored client to delete the customer in question?
    I would guess that this would give you an error and tell you why
    Freddy Kristiansen
    Group Program Manager, Client
    Microsoft Dynamics NAV
    http://blogs.msdn.com/freddyk

    The information in this post is provided "AS IS" with no warranties, and confers no rights. This post does not represent the thoughts, intentions, plans or strategies of my employer. It is solely my opinion.
  • Ravi_ThakkarRavi_Thakkar Member Posts: 392
    Yes. That's right.

    From NAV RTC or NAV C-side client, do the same process which you did on web.
    It will automatically bring you to an actual error.
    Ravi_Thakkar
    Ahmedabad, Gujarat, India
    E Mail : ravi.thakkar@hotmail.com
Sign In or Register to comment.