How do I get the value of an Attribute of Object through a JavaScript Action

0
Hi, All How do I get the value of an Attribute of Object using JavaScript Action? Here's my code, which returns empty         // This file was generated by Mendix Studio Pro. // // WARNING: Only the following code will be retained when actions are regenerated: // - the import list // - the code between BEGIN USER CODE and END USER CODE // - the code between BEGIN EXTRA CODE and END EXTRA CODE // Other code you write will be lost the next time you deploy the project. import "mx-global"; import { Big } from "big.js";   // BEGIN EXTRA CODE // END EXTRA CODE   /** * @param {MxObject} projectCompletionDateObject * @param {string} attributeName * @returns {Promise.<string>} */ export async function GetAttributeValue(projectCompletionDateObject, attributeName) { // BEGIN USER CODE const value = projectCompletionDateObject[attributeName]; return value; // END USER CODE }
asked
1 answers
2

Hi Chen,

     Here is the corrected code for your requirement, Here you need to pass the object and attribute name in the action get the value for attribute

 

// This file was generated by Mendix Studio Pro.

//// WARNING: Only the following code will be retained when actions are regenerated:

// - the import list

// - the code between BEGIN USER CODE and END USER CODE

// - the code between BEGIN EXTRA CODE and END EXTRA CODE

// Other code you write will be lost the next time you deploy the project.

import "mx-global";

import { Big } from "big.js";

// BEGIN EXTRA CODE// END EXTRA CODE

/** 

* @param {MxObject} projectCompletionDateObject 

* @param {string} attributeName 

* @returns {Promise.<string>} 

*/export async function GetAttributeValue(projectCompletionDateObject, attributeName)

{   

// BEGIN USER CODE   

const value = projectCompletionDateObject ? projectCompletionDateObject.get(attributeName) : undefined;   

return value;   

// END USER CODE

}

answered