Search code examples
javascriptcloudkit

How to assign reference to record using cloudkit js in custom zone?


This is what I have now:

var set = {
    recordType: 'Set', 
    fields: {
       name: { 
           value: 'AAB', 
           type: 'STRING' 
       },
       territory: {
           value: {
               recordName: "4CCA13D2-F52A-47D0-A690-46A556D0CB38",
               action: "DELETE_SELF", 
               zoneID: "territories"
           }, 
           type: "REFERENCE"
        }
    }, 
    zoneID: "territories"
};

I have created zone territories but this is succesfully saved to icloud but to default zone. Why?

The questions are:

  • How to assign a territory reference to my set record in my custom zone: territories.
  • How to save it in custom zone?

Solution

  • you need to add territory parent to this record:

    var set = {
        recordType: 'Set',
        fields: {
            name: { value: 'WWWWW', type: 'STRING' },
            territory: {
                value: {
                    recordName: "4CCA13D2-F52A-47D0-A690-46A556D0CB38",
                    action: "DELETE_SELF", zoneID: "territories"
                },
                type: "REFERENCE"
            }
        },
        zoneID: "territories",
        parent:
        {
            recordName: "4CCA13D2-F52A-47D0-A690-46A556D0CB38"
        }
    };