Sending back the dataset in jsdo invoke method - Forum - Mobile - Progress Community

Sending back the dataset in jsdo invoke method

 Forum

Sending back the dataset in jsdo invoke method

This question is answered

Hi,

I have an invokable method in my business entity. Catalog description for it is as follows:

{
"name": "GetWarnings",
"path": "\/GetWarnings",
"useBeforeImage": false,
"type": "invoke",
"verb": "put",
"params": [
{
"name": "dsWarning",
"type": "REQUEST_BODY"
},
{
"name": "plcParameter",
"type": "REQUEST_BODY"
}
]
}

I want to call the invoke method and pass in the dset and some additional parameter. The dataset is input-output in my method and want to merge the returned changes.

How can I pass the dset in addition to the paramater plcParameter.

Trying something like this, but it doesnt work.

// add record

jsdo.eWarning.add( { EntityType: 'AA', EntityRef: 'BB' } );

// setup param
var oParameter = { plcParameter: { EntityType: "Test1", EntityRef: "Test1" } };
var oParameterDS = jsdo._createChangeSet(jsdo._dataSetName, false);


jsdo.GetWarnings(oParameterDS, oParameter);

Verified Answer
  • Thanks for the advice.

    plcParameter is a serializable call parameter object. Could be anything e.g. character, integer, dset. In this case it is two char values. We are using the ConsultingWerk Generic Service Interface for JSDO (with Kendo UI dialect).

    Changed the code to use a single parameter object with 2 properties as you suggested and it seems to be building the request correctly now.

    We are subscribing to AfterInvoke event in which we handle the returned dataset, effectively replacing the one sent.

    We have a process whereby we need to send back the DS at one point to do some partial validation and also to populate other tables in the DS and perform specific calculations on the data...prior to SaveChanges.

    We looked at using getData() method but that seems to relate to a table. We need to send back the entire DS so using _createChangeSet() as that looked like the only method available to get what we wanted. Will you consider adding a publically available method in the API to achieve this ?

    Regards

All Replies
  • Hello,

    You only need to send one parameter to the invoke operation when using the name of the method.

    This single object parameter contains properties for each of the parameters that you are sending to the server.

    It would look like the following:

    jsdo.GetWarnings({

       "dsWarning": <value of dsWarning>,

       "plcParameter": <value of plcParameter>

    })

    The value for dsWarning is a DataSet so the value itself would have the name of the dataset and the name of the temp-table and the data as an array. You would see this in the Network tab. (See debugging tip below.)

    The method _createChangeSet() is consider to be internal and is not part of the public API.

    However, I can see that it does what you need which I am assuming is to get the values changed so that you can validate prior to performing saveChanges().

    Is plcParameter another DataSet or a Temp-Table?

    If it is a DataSet, it should have a similar structure to oParameterDS, i.e., it would have the name of the dataset and the name of the temp-table.

    If it is a Temp-Table, then it would only have the name of the temp-table and the data as an array.

    Once you fix oParameter, you should be able to change the call to GetWarnings to the following:

    jsdo.GetWarnings({

       "dsWarning": oParameterDS,

       "plcParameter": oParameter

    });

    Debugging Tip

    You can take a look at the request payload in the Network tab to confirm that the parameters are being sent.

    You should see something like the following:

    {
    	"request": {
    		"dsWarning": {
    			"dsWarning": {
    				"eEntity": [{
    					"EntityType": "Test1",
    					"EntityRef": "Test1"
    				}]
    			}
    		},
    		"plcParameter": {
    			"plcParameter": [{
    				"EntityType": "Test1",
    				"EntityRef": "Test1"
    			}]
    		}
    	}
    }

    Please notice that the request object that is sent to the server would have "dsWarning" twice, once as the name of the parameter and a second time as part of the structure of the DataSet.

    For the example above, I am using "plcParameter" as if it was a TEMP-TABLE.

    You can call invoke operations using the name of the method (as you have in your example):

       jsdo.GetWarnings(parameters);

    or using the invoke() method in the JSDO:

       jsdo.invoke("GetWarnings", parameters);

    The invoke operation is asynchronous by default. (When calling by name you can pass an additional parameter to make the call synchronous but this approach is not recommended since it would block the UI until the request completes.)

    To handle the response you would either need to subscribe to the AfterInvoke event or use a Promise.

    The documentation and the examples below show how to use both approaches:

       documentation.progress.com/.../

       oemobiledemo.progress.com/.../example004.html

       oemobiledemo.progress.com/.../example015.html

       oemobiledemo.progress.com/.../example016.html

    Please let me know if you need more information.

    I hope this helps.

  • Thanks for the advice.

    plcParameter is a serializable call parameter object. Could be anything e.g. character, integer, dset. In this case it is two char values. We are using the ConsultingWerk Generic Service Interface for JSDO (with Kendo UI dialect).

    Changed the code to use a single parameter object with 2 properties as you suggested and it seems to be building the request correctly now.

    We are subscribing to AfterInvoke event in which we handle the returned dataset, effectively replacing the one sent.

    We have a process whereby we need to send back the DS at one point to do some partial validation and also to populate other tables in the DS and perform specific calculations on the data...prior to SaveChanges.

    We looked at using getData() method but that seems to relate to a table. We need to send back the entire DS so using _createChangeSet() as that looked like the only method available to get what we wanted. Will you consider adding a publically available method in the API to achieve this ?

    Regards

  • You are welcome. I am glad to know that it is working now.

    The getData() method returns all the records in the JSDO memory.

    We have considered exposing a getChanges() method for this function and document it but this has not been done.

    (The getChanges() method is used internally by hasChanges().)

    Perhaps, we should expose _createChangeSet() or a variation of it.

    Something to mention is that _createChangeSet() would return a dataset with the before-image information as needed by the Submit operation.

    Depending on the requirements, you might want the changed records without the before-image information.

    (This is the intention of getChanges().)

    I will add a note to our backlog.

    Thank you for your suggestion.