Error on installation page with creating a schedule via SMI

So, i’m developing an application that connects to an external API via oauth.
I’m using a recurring schedule to keep the data synchronized between the external API and the local db (in FD)
I’ve created an iparams.html file for finetuned control for the end-user.
This settings-page works perfectly on local-testing

However, I could not get it to install without errors. By breaking the application apart, I’ve managed to find the culprit; I cannot set the schedule.

I’ve created a SMI-function in server.js:

    setUpSchedule: function(args){
        console.log(args)
        let dateString = args.date
        $schedule.create({
            name: "bedrijfsrooster",
            data: {recurring:true},
            schedule_at: dateString,
            repeat: {
                time_unit: "minutes",
                frequency: 5
            }
        }).then(function(data) {
            renderData(null,data)
        }, function(error){
            renderData(error)
        })
    }

I’m calling this SMI-function from a function in iparams.js:

function setUpScheduleSmi(){
    let date = Date.now();
    let dateString = new Date(date+(10*60000)).toISOString();
    let options = {"date":dateString};
    let button = document.getElementById('scheduleButton')
    client.request.invoke("setUpSchedule",options).then(
        function(data) {
            button.classList.toggle("btn-default");
            button.classList.toggle("btn-success")
            console.log(data);
        }, function(error) {
            button.classList.toggle("btn-default");
            button.classList.toggle("btn-danger");
            console.log(error);
        }
    )
}

this is the options object that’s being sent:

{ date: '2021-10-13T08:57:39.908Z', iparams: { __meta: { secure: [Array] }, api_key: '***********', domain: '***' }, isInstall: false, account_id: *******, region: 'EUC' }

I get the following error:
frontend:

errorSource: "APP"
message: "Schedule event could not be created"
requestID: "9587c2eb-b7f6-45b1-bda9-49f6e1a68687"
status: 400

I hope anyone can shed some light on the cause of this error.

1 Like

@Jeroen ,
Good Day!
Iparams has limited access to the platform services such as RequestAPI, SMI, and DB ( DB will be able to use after the app is installed) but Scheduler is not supported in Iparams

Kindly refer to this doc for more reference :slight_smile:

Note: In the custom installation page, only Request method and SMI are supported by the platform and can be used by initializing the client.

Hope it helps

Thanks

1 Like

Hi @Santhosh , thanks for your quick reply :slight_smile:

To be sure; i’m not calling Schedule from the iparams page; I’m calling a serverless SMI function, which in it’s turn calls the Scheduler. Since SMI is supported, i figured this was the way to go.
Are you saying that this assumption was not correct?

I’ve also tried this via the serverless side of the application at the onAppInstall event,.
I’ll try again, since my codebase has altered slightly, but I could not manage to install when I tried to setup a schedule on the appInstallEvent.

1 Like

@Jeroen ,
As we mentioned in the document, only Request Method and SMI is allowed in Iparams,
We won’t allow it even if you are calling the scheduler from SMI, Because SMI is called from Iparams page.

Hope it helps

1 Like

@Santhosh
Thanks, it does help. Time to try a different approach :smiley:
Have a nice day!

2 Likes

For anybody finding this issue: Setting the schedule in the onAppInstall-event did the trick.
However, did have to add renderData-functions in the resolvers, like this:

    onAppInstallCallback: function(args){
        let dateString = new Date(Date.now()+(6*60000)).toISOString();
        $schedule.create({
            name: "bedrijfsrooster",
            data: {recurring:true},
            schedule_at: dateString,
             repeat: {
                time_unit: "minutes",
                frequency: 5
            }
        }).then(function(data) {
            renderData(null,data)
        }, function(error){
            renderData(error);
        })
    }

I could not see this mentioned in the docks, but I found out after local testing.
I got the following message (after my console.log):

{ status: 400, message: 'This Schedule name already exists' }
`renderData` was not called in the callback within time limit!

Perhaps @Santhosh could elaborate on that, but I’ve got it working.

This topic was automatically closed 6 days after the last reply. New replies are no longer allowed.