1. Thomas Rolseth
  2. SnapDevelop
  3. Wednesday, 13 November 2019 15:30 PM UTC

In my PowerBuilder Client, I want to use the JsonPackage object to send the result sets of two datastores to our Web API that was created with SnapDevelop.  Here is my PB code:

//set values of JSONPackage with API datastores
ljpk_submit.setvalue( "Partials", ids, True)
ljpk_submit.setvalue( "Codes", ids2, True)

rc = g_APIClient.Submit(gs_webapi_url + is_controller + "/assigncode",is_response,ljpk_submit)

Now I need to loop through and do processing on the submitted rows for each datastore.  What is the best way to do that in my API controller?  Mainly I need to extract each datastore from the package but am unclear on how to do that. Below is my controller code.  Thanks, Tom

 

        [HttpPost]
        [ProducesResponseType(StatusCodes.Status500InternalServerError)]
        public ActionResult<IDataPacker> ClientAction(IDataUnpacker unpacker)
        {
            try
            {
                var packer = new DataPacker();

                ???


                return Ok();
            }
            catch (Exception ex)
            {
                return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
            }
        }    

Accepted Answer
Logan Liu @Appeon Accepted Answer Pending Moderation
  1. Thursday, 14 November 2019 03:29 AM UTC
  2. SnapDevelop
  3. # Permalink

Hi Thoma,

You can try the IDataUnpacker.GetDataStore() method:

https://docs.appeon.com/appeon_online_help/powerbuilder/api_reference/PowerBuilder.Data/DataStoreExtensions/Method/GetDataStore.html

sing SnapObjects.Data;
using PowerBuilder.Data;
using System;

namespace Appeon.ApiDoc.DataStoreExtensionsExamples
{
    public class GetDataStoreExample
    {
        private readonly SchoolContext _context;

        public GetDataStoreExample(SchoolContext dataContext)
        {
            // Sets the data context.
            _context = dataContext;
        }

        public void Example1(IDataUnpacker dataUnpacker)
        {
            // Gets the DataStore object from dataUnPacker according to the key
            var ds = dataUnpacker.GetDataStore("student");

            // Shows the students.
            for (int i = 0; i < ds.RowCount; i++)
            {
                Console.WriteLine("Row Status: {0}",
                    ds.GetRowStatus(i));

                Console.WriteLine("First Name: {0}",
                    ds.GetItem<string>(i, "FirstName"));
                Console.WriteLine("Last Name: {0}",
                    ds.GetItem<string>(i, "LastName"));

                Console.WriteLine();
            }

            /* This code example produces the following output:
            
            Row Status: NewModified
            First Name: Lena
            Last Name: Sherwood

            Row Status: NewModified
            First Name: Davies
            Last Name: Adam
            */
        }
    }
}

Regards,

Logan

Comment
There are no comments made yet.
Thomas Rolseth Accepted Answer Pending Moderation
  1. Friday, 15 November 2019 18:45 PM UTC
  2. SnapDevelop
  3. # 1

Kevin, Logan -- thank you both.  I'm going with the GetDataStore() approach given what I need to do after getting a handle on the jsonpackage components.  It's working nicely so far. 

Tom

Comment
There are no comments made yet.
Kevin Ridley Accepted Answer Pending Moderation
  1. Thursday, 14 November 2019 15:12 PM UTC
  2. SnapDevelop
  3. # 2

I haven't used Snap yet, but I think what you want to do after your 2 package.SetValue() lines is, package.GetJSONString() and then pass the string to your Snap component.  On the component side, create your package object and do package.LoadString(), then to get each of the data items do package.GetValue().  Then you can do datastore.ImportJSON() for each.  Hopefuly that's what you were looking for.

Comment
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.