Examples
- Last UpdatedNov 27, 2018
- 1 minute read
How to update Formulas
This script example shows how to update Formula values so that it can be used at runtime.
dim rmpConnection = new RMPClientAPI.ClientConnection("RMP_HostName", "UserName", "Password");
dim formulaAPI = new RMPClientAPI.FormulaAPI(rmpConnection);
dim formulaParameterAPI = new RMPClientAPI.FormulaParameterAPI(rmpConnection);
dim formula as RMPClientAPI.Formula;
dim parameter as RMPClientAPI.FormulaParameter;
dim parameters as System.Collections.ICollection;
' Checkout the formula so it can be updated.
formula = formulaAPI.CheckOut("F_003");
parameters = formulaParameterAPI.GetAll(formula.Name);
' find and update the parameters
for each parameter in parameters
if (parameter.Name == "Param01") then
parameter.Target = false;
formulaParameterAPI.Change(parameter);
elseif (parameter.Name == "Param02") then
parameter.Target = 11;
formulaParameterAPI.Change(parameter);
elseif (parameter.Name == "Param03") then
parameter.Target = 123.321;
formulaParameterAPI.Change(parameter);
elseif (parameter.Name == "Param04") then
parameter.Target = "String Value";
formulaParameterAPI.Change(parameter);
endif;
next;
' CheckIn and Approve
formulaAPI.CheckIn(formula);
formulaAPI.SetState(formula, RMPClientAPI.ModelStates.Approved, "Parameters values updated.");
How to update Custom Values
You need to have a particular set of configurations for this example.
The system has the following ListTypes configured:
-
MixerSpeeds - EnumList
-
Fast = 75
-
Slow = 25
-
Off = 0
-
-
Locations - StringList
-
Line01
-
Line02
-
There is a global extension named Location defined as Locations.
A Formula has a parameter named "Speed" defined as MixerSpeeds.
This example will update the parameter "Speed" to have a target value of Fast and its extension value set to "Line01".
dim formula = formulaAPI.CheckOut("F_001");
dim parameter = formulaParameterAPI.GetOne(formula.Name, "Speed");
parameter.Target = 75; 'Fast
parameter.ExtValues["Location"] = "Line01";
formulaParameterAPI.Change(parameter);
formulaAPI.CheckIn(formula);