InsertQuery with SubQuery

I'm using DataService's web service to create new records in a simple custom object (via {{BaseUri}}/0/DataService/json/SyncReply/InsertQuery). 

This object/section has a lookup to Contact, and so far in the body of the request I have been sending each Contact Id like this:

"ContactLkp": {
  "expressionType": 2,
  "parameter": {
    "dataValueType": 10,
    "value": "6530f9b7-2ca2-48a6-b529-fbfd456aa704"
  }
}

However, for this to work, it is a prerequisite to previously having searched each contact's Id vía SelectQuery.

 

My question is, could it be possible to insert the contact by using a subQuery? It seems like it should according to this documentation (by using an expressionType of value 3), but I have been unable to create a successful subQuery/subFilter. 

What I would like to do is something like this:

"ContactLkp": {
  "expressionType": 3,
  "subQuery": {
     // Use a select query by using a parameter like the name 
     // or the email of the contact
 
  }
}

With this I would be able to insert the record with only 1 request (insert) instead of 2 (select/search and then insert).

 

TL;DR, is it possible to include subqueries as parameters in DataService's InsertQuery?

Like 0

Like

2 comments
Best reply

Hello,

If I understand you correctly, you are trying to do something like this "INSERT INTO Contact (OwnerId) VALUES ((SELECT Id FROM Contact WHERE Name = 'Test1'))", select inside of the insert.

Unfortunately, currently, it is impossible to do so and you need to use two requests, first Select and second Insert as you did before.

Parameter SubQuety isn't designed for this situation and you write select requests inside of it.

{
                "ActivitiesCount",
                new SelectQueryColumn ()
                {
                    Expression = new ColumnExpression ()
                    {
                        // Expression - subquery.
                        ExpressionType = EntitySchemaQueryExpressionType.SubQuery,
                        // Path to the column relative to the root schema.
                        ColumnPath = "[Activity: Contact] .Id",
                        // Function type - aggregating.
                        FunctionType = FunctionType.Aggregation,
                        // Aggregation type - number.
                        AggregationType = AggregationType.Count
                    }
                }
            }

 

We already created a problem for our developers so that you can achieve your task using only one request, thank you for helping us improve the system.

 

Hello,

If I understand you correctly, you are trying to do something like this "INSERT INTO Contact (OwnerId) VALUES ((SELECT Id FROM Contact WHERE Name = 'Test1'))", select inside of the insert.

Unfortunately, currently, it is impossible to do so and you need to use two requests, first Select and second Insert as you did before.

Parameter SubQuety isn't designed for this situation and you write select requests inside of it.

{
                "ActivitiesCount",
                new SelectQueryColumn ()
                {
                    Expression = new ColumnExpression ()
                    {
                        // Expression - subquery.
                        ExpressionType = EntitySchemaQueryExpressionType.SubQuery,
                        // Path to the column relative to the root schema.
                        ColumnPath = "[Activity: Contact] .Id",
                        // Function type - aggregating.
                        FunctionType = FunctionType.Aggregation,
                        // Aggregation type - number.
                        AggregationType = AggregationType.Count
                    }
                }
            }

 

We already created a problem for our developers so that you can achieve your task using only one request, thank you for helping us improve the system.

 

Thank you for your kind reply. I will continue to do as suggested. 

Show all comments