For a project, we might need to re-link function resources to new rows in the function's entry table when the user either resets or manually re-allocates the device's resources. I know this information resides in the Generic DVE Linker table but instead of modifying the table directly, I should use the ResourceManager API for such changes, as it will ensure to update internal cache references.
Could you please provide an example of an automation script for such a change? Ideally, I would like to give an instance of a FunctionResource and a primary key, such that the resource should be linked to the new specified row after a successful execution.
Based on the answer to this other question, I created a test script to modify the link of a FunctionResource. The following code snippet assumes that the script receives a resource's GUI, a new primary key, and a table entry parameter id.
The script is referencing our SLSRMLibrary for easy access to the ResourceManager:
var resourceManager = SrmManagers.ResourceManager;
// Get the FunctionResource, main element and function element
var resource = (FunctionResource)resourceManager.GetResource(
Guid.Parse(engine.GetScriptParamValue<string>("FunctionResourceId"))) ??
throw new Exception($"Resource {engine.GetScriptParamValue<string>("FunctionResourceId")} not found");
// List the current entry points
foreach (Tuple<int, string> entry in resource.LinkerTableEntries)
{
engine.GenerateInformation($"DEBUG:({entry.Item1},{entry.Item2})");
}
// Setting a new PK. No extra validation, so the new values are assumed to be valid
var newPK = engine.GetScriptParamValue<string>("NewPK");
var newTableId = engine.GetScriptParamValue<int>("TableId");
resource.PK = newPK;
resource.LinkerTableEntries = new Tuple<int, string>[]
{
new Tuple<int, string>(newTableId, newPK),
};
resourceManager.AddOrUpdateResources(new Resource[] { resource });
You an find a code snippet in following question : https://community.dataminer.services/question/code-for-setresourcemessage-request
Thanks, Emmanuel.
Be aware that changing the link to a new entry point row might require re-opening the resource in Cube to have an updated view of the information.