Skip to content
This repository has been archived by the owner on Jan 20, 2024. It is now read-only.

Schedule soap action: "Cannot set property '$' of undefined" #144

Closed
avishayg opened this issue Feb 28, 2021 · 1 comment
Closed

Schedule soap action: "Cannot set property '$' of undefined" #144

avishayg opened this issue Feb 28, 2021 · 1 comment

Comments

@avishayg
Copy link

avishayg commented Feb 28, 2021

Hi,
I'm using this package and tackled some bug with scheduling an Email Send Definition:
https://developer.salesforce.com/docs/atlas.en-us.noversion.mc-apis.meta/mc-apis/scheduling_an_email_send_definition.htm

I'm trying to run this code to preform the action:

schedule() {
   ...

    const scheduleOpts = {
        Recurrence: {
            DailyRecurrencePatternType: 'Interval',
            DayInterval: 1,
        },
        RecurrenceType: 'Daily',
        RecurrenceRangeType: 'EndAfter',
        StartDateTime: '2021-02-28T22:00:00+02:00',
    }
    const interactions = { CustomerKey: ${EMAIL_DEFINITION_KEY} };

    return new Promise((resolve, reject) => {
        this.soapClient.schedule('EmailSendDefinition', scheduleOpts, interactions, 'start', null, (err, response) => {
            if (err) reject(err);
            else resolve(response.body);
        });
    });
}

But I get this error:

TypeError: Cannot set property '$' of undefined
    at FuelSoap.schedule (node_modules/fuel-soap/lib/fuel-soap.js:663:54)
    ....

Looking at the code I can see that there is an assignment to undefined property (in lib/fuel-soap.js line 663)

if(Array.isArray(body.ScheduleRequestMsg.Interactions)){
	for(let i = 0; i < body.ScheduleRequestMsg.Interactions.length; i++){
		body.ScheduleRequestMsg.Interactions[0].Interaction.$ = {'xsi:type': type};
	 }
} else if (typeof body.ScheduleRequestMsg.Interactions === "object") {
	body.ScheduleRequestMsg.Interactions.Interaction.$ = {'xsi:type': type};
} else {
	throw new TypeError('Interactions must be of Array or Object Type');
}

You can't assume that body.ScheduleRequestMsg.Interactions.Interaction.$ is set since you get it from outside.

Not sure this is a bug or I missed something in the docs (also didn't find much relevant docs on how to use the schedule action).
My version is 2.2.4

Thanks
Avishay

@avishayg
Copy link
Author

Found the mistake, closing the issue

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant