// Check if model is provided
if (!model) {
console.warn("No form data (model) provided.");
return;
}
const { name, specificType } =model;
console.log("Searching entities with Name:", name, "and Specific Type:", specificType);
// Create the builder
varbuilder=$api.entitiesSearchBuilder().flattened();
// Define filters based on model values
varfilter= {
and: [
{
eq: {
'resourceType':'entity.device' }
}
]
};
if (name) {
filter.and.push({
like: {
'provision.administration.identifier':name// Assuming 'name' maps to identifier for this example, or use 'provision.device.name' if appropriate
}
});
}
if (specificType) {
filter.and.push({
eq: {
'provision.device.specificType':specificType }
});
}
// Apply filter if any conditions were added
if (filter.and.length>0) {
builder.filter(filter);
}
try {
// Execute the search
// await is supported in this context
constresponse=awaitbuilder.build().execute();
if (response.statusCode===200) {
console.log("--- Entity Search Results ---");
constentities=response.data.entities;
if (entities&&entities.length>0) {
console.table(entities.map(e => ({
id:e['provision.administration.identifier']._value._current.value,
specificType:e['provision.device.specificType'] ?e['provision.device.specificType']._value._current.value:'N/A' })));
console.log("Total entities found:", entities.length);
} else {
console.log("No entities match the criteria.");
}
} else {
console.error("Search failed with status:", response.statusCode);
}
} catch (err) {
console.error("Error executing entity search:", err);
}