on 06-08-2018 2:24 PM
Hi,
I use the following code to retrieve a userfield in the service layer.
var queryOption = "$select=TableName,FieldID&$filter=TableName eq '" + fieldData[i].TableName + "' and Name eq '" + fieldData[i].Name +
"'";
console.log('queryOption: ' + queryOption);
var rs = slContext.UserFieldsMD.query(queryOption);
console.log('rs: ' + JSON.stringify(rs));
The syntax of the query options is good, but I don't know the format of rs.
JSON.stringify(rs) gives {}
How can I get the returned fields of how do I know nothing is returned.
Thanks
Ad
Hi Ad,
Have you tried the toArray() method as given in the SL User Manual?
function GET() {
var queryOption = "$select=CardName, CardCode & $filter=contains(CardCode, 'c1') & $top=5 & $orderby=CardCode";
var slContext = new ServiceLayerContext();
var retCaseSensitive = slContext.BusinessPartners.query(queryOption);
var retCaseInsensitive = slContext.query("BusinessPartners", queryOption, true);
http.response.setStatus(http.HttpStatus.HTTP_OK);
http.response.setContent({ "CaseSensitive": retCaseSensitive.toArray(), "CaseInsensitive": retCaseInsensitive.toArray() });
http.response.send();
I have tried in my environment and made it work with toArray():
var queryOption = "$select=TableName,FieldID,Name&$filter=TableName eq '@UDO_DOC' and Name eq 'CardCode'"; var slContext = new ServiceLayerContext();
var dataSrvRes = slContext.UserFieldsMD.query(queryOption);
http.response.send(http.HttpStatus.HTTP_NOT_FOUND, dataSrvRes.toArray());
Hope it helps,
Trinidad.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Trinidad,
What I am trying to do is on the server side to check if a userfield exist and according to the answer add or update a userfield
My query on postman works and gives a correct answer (see below).
https://xxxxxx:50000/b1s/v1/UserFieldsMD?$select=TableName,FieldID&$filter=TableName eq 'OHEM' and Name eq 'se_userscan'
{
"odata.metadata": "https://devhanadb01.serac.nl:50000/b1s/v1/$metadata#UserFieldsMD",
"value": [
{
"TableName": "OHEM",
"FieldID": 2
}
]
}
Regards
Ad
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Ad,
I'm not sure to understand what you are trying to do here.
You want to check if a specific field already exists in a table?
Does the query work on Postman? Can you please try it?
There is a sample in the SL User Guide:
Retrieving UDFs
To retrieve a UDF, send an HTTP request as the example below:
GET /UserFieldsMD(TableName='OCRD', FieldID=0)
For more information, see Retrieving Entities.
Querying UDFs
Standard OData query options are also supported for UDFs.
For example, you've forgotten the table name and the UDF ID but still remember the UDF name; you can query the UDF as follows:
GET /UserFieldsMD?$filter=Name eq 'u1'
The service returns:
{
"value": [
{
"Name": "u1",
"TableName": "ACRD",
"FieldID": 0,
...
...
},
{
"Name": "u1",
"TableName": "OCRD",
"FieldID": 0,
...
}
]
}
Thanks,
Trinidad.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
88 | |
10 | |
10 | |
9 | |
7 | |
7 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.