[IMPLEMENTED] Query contents from script

I have…

  • Read the following guideline: Troubleshooting and Support | Squidex. I understand that my support request might get deleted if I do not follow the guideline.
  • Used code blocks with ``` to format my code examples like JSON or logs properly.

I’m submitting a…

  • Regression (a behavior that stopped working in a new release)
  • Bug report
  • Performance issue
  • Documentation issue or request

Current behavior

I’ve script to check reference duplicates, but for that I need to send getJson to fetch contents

Expected behavior

Fetch content without getJson method

Minimal reproduction of the problem

if (ctx.data.nanu.iv) {
    const url = `${ctx.user.claims.iss[0]}api/content/${ctx.appName}/instruction?$filter=data/SKU/iv eq '${ctx.data.nanu.iv}'&$top=2`;
    
    const headers = {
        'Authorization': `Bearer token`
    };

    getJSON(url, (data) => {
         if (data.total > 0) {
                const isDuplicate = data.items.some(item => item.id !== ctx.contentId);

                if (isDuplicate) {
                    throw `Duplicate reference detected: cooking instruction with nanu already exist.`;
                }
            }
    }, headers);
}

Environment

App Name: Test-app

  • Self hosted with docker
  • Self hosted with IIS
  • Self hosted with other version
  • Cloud version

Version: latest

Browser:

  • Chrome (desktop)
  • Chrome (Android)
  • Chrome (iOS)
  • Firefox
  • Safari (desktop)
  • Safari (iOS)
  • IE
  • Edge

Others:

Looks okay, but what is the issue?

I want to make it without getJson, is it possible?

There is no method that avoids that at the moment. I might be able to provide something until early next week.

btw: there is also a unique validation property. If you have only one field like SKU you don’t need scripting.

Would be really amazing, to have it

My SKU field is reference to another schema, so could you please let me know how I can avoid a few records with the same reference?

I am sorry, I thought it is just a reference field. Why do you have 2 schemas at all if this is actually a one to one relationship?

I’ve complex schemas I have base schema A with SKU, and 3 others schemas which have reference to the schema A, anyway if you can migrate fetch to the scripting engine to give more flexibility(Scripting request bearer token not working - #4 by Sebastian) that would be enough to me

1 Like

I have added a new method to get contents:

getContents('schema', { query: '$filter=...' }, function (contents) {

});

OR

getContents('schema', '$filter=...', function (contents) {

});