DRB icon indicating copy to clipboard operation
DRB copied to clipboard

Invalid javascript generated for custom API

Open skfd opened this issue 1 year ago • 2 comments

Latest version of the tool. I think it should drop the symbols that are valid for custom API, but invalid for javascript. Stringify the parameters.

Something else is probably wrong, I'm also getting "The request URI is not valid. The segment 'ilac_GroupBookingItemPrice' cannot include key predicates, however it may end with empty parenthesis." error...

This:

var execute_ilac_GroupBookingItemPrice_Request = {
	// Parameters
	GroupBookingItemPrice-In-ProductIds: {guid: "27a03987-69b3-ef11-a730-000d3af3976a" }, // Edm.Guid
	GroupBookingItemPrice-In-WeeksCount: 2, // Edm.Int32
	GroupBookingItemPrice-In-CurrencyId: {guid: "89de3277-03b7-ed11-a37e-002248b12501" }, // Edm.Guid

	getMetadata: function () {
		return {
			boundParameter: null,
			parameterTypes: {
				GroupBookingItemPrice-In-ProductIds: { typeName: "Edm.Guid", structuralProperty: 1 },
				GroupBookingItemPrice-In-WeeksCount: { typeName: "Edm.Int32", structuralProperty: 1 },
				GroupBookingItemPrice-In-CurrencyId: { typeName: "Edm.Guid", structuralProperty: 1 }
			},
			operationType: 1, operationName: "ilac_GroupBookingItemPrice"
		};
	}
};

Xrm.WebApi.execute(execute_ilac_GroupBookingItemPrice_Request).then(
	function success(response) {
		if (response.ok) { return response.json(); }
	}
).then(function (responseBody) {
	var result = responseBody;
	console.log(result);
	// Return Type: mscrm.ilac_GroupBookingItemPriceResponse
	// Output Parameters
	var groupbookingitemprice-out-price = result["GroupBookingItemPrice-Out-Price"]; // Edm.Decimal
}).catch(function (error) {
	console.log(error.message);
});

Should be generated like this:

var execute_ilac_GroupBookingItemPrice_Request = {
	// Parameters
	'GroupBookingItemPrice-In-ProductIds': {guid: "27a03987-69b3-ef11-a730-000d3af3976a" }, // Edm.Guid
	'GroupBookingItemPrice-In-WeeksCount': 2, // Edm.Int32
	'GroupBookingItemPrice-In-CurrencyId': {guid: "89de3277-03b7-ed11-a37e-002248b12501" }, // Edm.Guid

	getMetadata: function () {
		return {
			boundParameter: null,
			parameterTypes: {
				"GroupBookingItemPrice-In-ProductIds": { typeName: "Edm.Guid", structuralProperty: 1 },
				"GroupBookingItemPrice-In-WeeksCount": { typeName: "Edm.Int32", structuralProperty: 1 },
				"GroupBookingItemPrice-In-CurrencyId": { typeName: "Edm.Guid", structuralProperty: 1 }
			},
			operationType: 1, operationName: "ilac_GroupBookingItemPrice"
		};
	}
};

Xrm.WebApi.execute(execute_ilac_GroupBookingItemPrice_Request).then(
	function success(response) {
		if (response.ok) { return response.json(); }
	}
).then(function (responseBody) {
	var result = responseBody;
	console.log(result);
	// Return Type: mscrm.ilac_GroupBookingItemPriceResponse
	// Output Parameters
	var groupbookingitemprice_out_price = result["GroupBookingItemPrice-Out-Price"]; // Edm.Decimal
}).catch(function (error) {
	console.log(error.message);
});

skfd avatar Dec 20 '24 20:12 skfd

Hi, I understand the issue but I don't know if the error you are getting is related to the JS generated or by something else, you can try to test the Custom API with another tool like Custom API Tester.

About the main issue (how the code is generated) I don't know when a fix will be available, I will keep the issue opened, feel free to submit a pull request if you want to fix this in the main branch. Thanks for reporting it.

GuidoPreite avatar Dec 20 '24 22:12 GuidoPreite

Absolutely no problem, I understood the problem and created valid names, and genarator gave correct code. It's just an edge cases exacerbated by defaults of Custom API Manager tool, hehe. It loves dashes! image

skfd avatar Jan 03 '25 06:01 skfd