Your object references seem to be out of sync! When you call getSourceFieldDetails
, it causes the objects referenced by field
and sf_detail
to become different.
The Issue
In the script's beginning, an object is created:
{
Name: 'Test',
Label: 'Data',
Type: 'Boolean'
};
This object is then assigned a reference named sf_detail
.
In the code block where sf_detail_info
is defined, field
is set to reference the same object as sf_detail
:
data: {
field: sf_detail
}
However, in the function getSourceFieldDetails
, sf_detail
is updated to point to a new object. This means that while sf_detail
now points to the new object, field
still holds a reference to the old one.
The Resolution
To resolve this issue, avoid assigning a new object to sf_detail
. Instead, update the properties of the existing object. The revised version of getSourceFieldDetails
looks like this:
function getSourceFieldDetails(val) {
// This would typically fetch data from an API endpoint
console.log(val[0]);
sf_detail.Name = val[0];
sf_detail.Label = val[0] + 'Label';
sf_detail.Type = val[0] + 'DataType';
console.dir(sf_detail);
}
You can find a modified version of your original fiddle here with the necessary changes incorporated.