Unable to retrieve associations of an object in Javascript action. Returning empty array.

0
I used object.getReferences("Module.Ref") and other related methods in my Javascript action and it is return an empty array but in the nanoflow we are able to get correct values using retrieve action by association.
asked
2 answers
0

Hi Saumyajeet,

Is it possible to retrieve the list before the JavaScript action and passing it into the action as a parameter? That would be the recommended approach here. 

answered
1

As pointed out by Marius you won't be able to fetch references of 1-* association from parent directly as they are not stored there. You can alternatively fetch it as shown in code below -

export async function JS_Catalog(catalog) {
	// BEGIN USER CODE
	// Catalog has many CatalogItems
	// Instead of catalog.getReferences("MainModule.CatalogItem"));
	console.info(`Catalog: ${catalog.get("Name")}`); // Name is attribute in Catalog entity
	mx.data.get({
		guid: catalog._guid,
		path: "MainModule.CatalogItem_Catalog",
		callback: objs => {
			objs.forEach(obj => {
				console.info(`Col: ${obj.get("Name")}`);  // Name is attribute in CatalogItem entity
			})			
		}
	})

	// throw new Error("JavaScript action was not implemented");
	// END USER CODE
}

 

answered