Skip to content

Error handling DateTime parameters with Xrm.WebApi syntax for Custom APIs, Custom Actions and Actions #35

@GuidoPreite

Description

@GuidoPreite

Example

var execute_new_TestDate_Request = {
	// Parameters
	InputDate: new Date("2025-03-01 11:16").toISOString(), // Edm.DateTimeOffset

	getMetadata: function () {
		return {
			boundParameter: null,
			parameterTypes: {
				InputDate: { typeName: "Edm.DateTimeOffset", structuralProperty: 1 }
			},
			operationType: 0, operationName: "new_TestDate"
		};
	}
};

The Xrm.WebApi syntax is not doing a JSON.stringify of the parameters (with other syntaxes like Fetch the body is created using JSON.stringify) and for DateTime parameters the generated string causes an error.
Temporary fix is to stringify the DateTime parameter, example:

InputDate: JSON.stringify(new Date("2025-03-01 11:16").toISOString()), // Edm.DateTimeOffset

or to add quotes around the value:
InputDate: "'" + new Date("2025-03-01 11:16").toISOString() + "'", // Edm.DateTimeOffset

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions