1

Specifically in NAV 2013. When I look up a record using a Page webservice, I get a response something like the following:

<Soap:Envelope xmlns:Soap="http://schemas.xmlsoap.org/soap/envelope/">
    <Soap:Body>
        <ReadMultiple_Result xmlns="urn:microsoft-dynamics-schemas/page/[PAGENAME]">
            <ReadMultiple_Result>
                <[RECORDNAME]>
                    <Key>##;[KEYSTUFF KEYSTUFF KEYSTUFF];[OTHER KEYSTUFF];</Key>
                    <[OTHERFIELD]>[OTHERDATA]</[OTHERFIELD]>
                </[RECORDNAME]>
            </ReadMultiple_Result>
        </ReadMultiple_Result>
    </Soap:Body>
</Soap:Envelope>

... and then, if I want to interact with that record to do an Update or Delete through the webservice, I have to use the Key field to refer to it directly.

What I want to know is if I can expose an XMLPort through a Codeunit webservice, and still export that Key field directly, or if I'll have to do some separate lookup to add it to the export for each row? Or if it might just make more sense to expose this info as a page since I'm planning on interacting with the records?

Jason
  • 13,606
  • 2
  • 29
  • 40
  • So you want to read records from table through xmlport in exposed codeunit and update them through exposed page? Why? – Mak Sim Apr 26 '14 at 09:17
  • 1
    If I'm not mistaking key contains some kind of timestamp that allows to check if record was already modified since its been read from db. So one can't overwrite record. When you use codeunits you loose this option. To do what you want you would need some C/AL function that generates key for record. I don't know such function. – Mak Sim Apr 26 '14 at 09:22
  • My intention was to read and update through the codeunit (because I have no need for this data to be accessible through a page), providing the key so that I wouldn't have to pass all of the fields in the actual primary key. Since asking the question I just went with doing it with a page anyway. But by your comment, it sounds like the Key is transient rather than something I can definitely rely on, which starts to give me some sense of why it's not used as a primary key the way I'm used to thinking about it. So thanks for that. If you want to add your comment as an answer I'll accept it. – Jason Apr 28 '14 at 12:16
  • @Jason Where you able to solve this in some kind of way? – lanoxx Sep 18 '14 at 08:00
  • Yeah, I just used a page to look up and update the record I wanted rather than trying to get cute and do all this behind the scenes in a codeunit. – Jason Sep 18 '14 at 13:04

1 Answers1

1

In this question a guy states that

that at least part of the key is a Base64 encoded string of the columns that make up the primary key

so the first part of the key is some kind of salt or timestamp that is used to avoid overwriting record when updating through exposed page.

There is no function in Nav that allows to calculate web-service key for certain record and no way to use this key in C/AL to fetch record.

If your intention is to use exposed codeunit to both read and write you can use XML port with Direction property set to Both as the parameter of procedure to read and update record in certain table(s). Of course in that case you have to use all primary key fields in XML Port to identify record.

Community
  • 1
  • 1
Mak Sim
  • 2,148
  • 19
  • 30
  • I somehow missed that you had posted this as an answer, and thanks for the link to add a little exposition. – Jason May 09 '14 at 13:33